main

Is ‘int main;’ a valid C/C++ program?

萝らか妹 提交于 2019-11-29 20:46:55
I ask because my compiler seems to think so, even though I don’t. echo 'int main;' | cc -x c - -Wall echo 'int main;' | c++ -x c++ - -Wall Clang issues no warning or error with this, and gcc issues only the meek warning: 'main' is usually a function [-Wmain] , but only when compiled as C. Specifying a -std= doesn’t seem to matter. Otherwise, it compiles and links fine. But on execution, it terminates immediately with SIGBUS (for me). Reading through the (excellent) answers at What should main() return in C and C++? and a quick grep through the language specs, it would certainly seem to me that

Compile and run program without main() in C

删除回忆录丶 提交于 2019-11-29 19:30:36
I'm trying to compile and run following program without main() function in C . I have compiled my program using the following command. gcc -nostartfiles nomain.c And compiler gives warning /usr/bin/ld: warning: cannot find entry symbol _start; defaulting to 0000000000400340 Ok, No problem. then, I have run executable file(a.out), both printf statements print successfully, and then get segmentation fault . So, my question is, Why segmentation fault after successfully execute print statements? my code: #include <stdio.h> void nomain() { printf("Hello World...\n"); printf("Successfully run

How to get rid of SIGTERM error

六眼飞鱼酱① 提交于 2019-11-29 18:51:49
问题 i have been working on this iphone app in the new xcode4. Practically every time I exit my application in the simulator I get an error on a code line in the main.m Here is my line of code, and then the error on the next line int retVal = UIApplicationMain(argc, argv, nil, nil); Thread 1:Program received signal: "SIGTERM". What is happening here? How do I fix this? 回答1: SIGTERM is a Unix signal, used to tell your program to quit (TERMinate). When you run your program in Xcode, it runs it

main() function defined without return type gives warning

99封情书 提交于 2019-11-29 18:02:36
This is my program: main() { printf("hello world\n"); } I get this warning when compiling it: function should return a value When changing main() to void main() , the warning disappears. Why is that so? There are few things which you should take note of : The int is the main() function's return type. That means that the kind of value main() can return is an integer. main( ) was tolerated by the C90 compilers but not by C99 compilers which means its not a part of C99 standard anymore , so don't do this. void main() is not a standard form ,some compilers allow this, but none of the standards

C++ what to code if i put a class after main() function

╄→尐↘猪︶ㄣ 提交于 2019-11-29 15:32:10
问题 I'm watching some video tutorials on C++ and i know you must define a function / class before it is used or called. But I like having my main() function at the top, and everything else below the main function. I know if i define a function below the main function I must declare it before it is used, but what about a class? What do I need to put above my main function to use my class below the main function. #include <iostream> using namespace std; int main() { ClassOne one; one.coolSaying();

Where and why JVM checks that the return type of entry method main(String args[]) is void and not anything else?

这一生的挚爱 提交于 2019-11-29 15:22:49
I will try to answer both, please correct me if I am wrong: Where: If a static method is being called using Classname .method() or using reflection then it doesn’t matter even if you change the return type of the calling method, the same method will still be called. So JVM probably checks this in one of the native methods of jvm.cpp methodHandle m (THREAD, init_klass->find_method(vmSymbols::object_initializer_name(),> vmSymbols:: void_method_signature() )); if (m.is_null()) { ------ THROW_MSG_0 ……….. Why: Although its useless to return a value from main, as java does not do anything with it

What is the purpose of the returning of a value from main() in C/C++? [duplicate]

纵饮孤独 提交于 2019-11-29 15:15:37
Possible Duplicates: main() functions return value? What should main() return in C/C++? What is the purpose of the returning of a value from main() in the languages C and C++? How the return value helps us? Can the return value be used to achieve anything important? It's the exit status . It's typically used to signal to the OS whether the process was successful or not in whatever it was doing. It indicates the execution status of the program. Usually zero means it went fine. On most operating systems, the return value becomes the value returned from the process when it exits. By convention, a

how to get the command line arguments from another class with java

安稳与你 提交于 2019-11-29 13:17:15
so suppose I have a java package.... it's got the main class with the main method and then it's got a whole bunch of other classes..... my question is, is it possible to get the args that was passed into the main method from these other classes that are not part of the main class but in the same package... paxdiablo No, not portably, there may be some trickery based on the JVM implementation but I've never seen it, and it would be a very bad idea to rely on it even if it existed. If you want those values elsewhere, the main function needs to make them available somehow. An easy way to do this

Doxygen not documenting main function in main.cpp

拟墨画扇 提交于 2019-11-29 11:54:41
问题 I have a main.cpp that contains a struct, some global constants and a main function. I ran doxygen and the only documentation I am getting in the output index.html is for my struct. I want doxygen to document into that index.html file my main() as well. What am I doing incorrectly? /// Definition of Pi const auto Pi = 3.141592653589793238462643383279502884197169399; /// \struct myStruc /// \brief myStruc description /// struct myStruc { /// Comments inside myStruc }; /// \file /// \brief Main

Compiling with int main(void) fails; main(int argc, char *argv[]) succeeds. Why?

半腔热情 提交于 2019-11-29 11:05:56
Problem Why would compiling a program which has an int main(void) main function differ from compiling a program which has an int main(int argc, char *argv[]) main function, if the program does not use arguments passed on the command line? Is this OS or compiler specific? I do not get the same results using mingw and g++ (which is weird isn't it as wingw is a port of gcc) . Example Code #include <iostream> #include"SDL/SDL.h" int main(void) { return 0; } Compilation commands g++ test.cpp; #g++ 4.4.5 i586-mingw32msvc-g++ test.cpp; # mingw 4.4.4 Error (Given by the second command.) a(main.o):(