Where did you get that from?
- Dire
whats the point of -> void main();
[email=direwolf@digitalfiends.com]Dire Wolf[/email]
www.digitalfiends.com
www.digitalfiends.com
Dire, perhaps you're talking about C, not C++? I'm not sure about C, but the ANSI/ISO C++ Standard requires the compiler to accept
and
Any other types of declarations for main() will make your code less portable.
Edited by - spock on November 24, 2000 9:32:15 PM
int main() { /* ... */ }
and
int main(int argc,char* argv[]) { /* ... */ }
Any other types of declarations for main() will make your code less portable.
Edited by - spock on November 24, 2000 9:32:15 PM
IFAIK:
The ANSI C requires a non void type; it doesn''t have to be an int; the typical return type is an int.
ANSI C (& C++) specific 0 as the value given to false, everything else it true. The typical thing to do it set true to -1 (not 1), because every bit of true & false will now be different, not just the first bit. 0 (false) is returned on success because there is only one way to succeed, and many ways to fail.
C++ can have any base type returned from main, maybe even user declared types as well, though I''ve never tried.
I think MSVC returns a bogus value to the OS for you, if you declare main with a void return. I suspect other compilers also do this for you, except the compiler/OS ImmaGNUman mentioned it casued an error...
The ANSI C requires a non void type; it doesn''t have to be an int; the typical return type is an int.
ANSI C (& C++) specific 0 as the value given to false, everything else it true. The typical thing to do it set true to -1 (not 1), because every bit of true & false will now be different, not just the first bit. 0 (false) is returned on success because there is only one way to succeed, and many ways to fail.
C++ can have any base type returned from main, maybe even user declared types as well, though I''ve never tried.
I think MSVC returns a bogus value to the OS for you, if you declare main with a void return. I suspect other compilers also do this for you, except the compiler/OS ImmaGNUman mentioned it casued an error...
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
I was always taught to return an int from main() so the standard is cool with me
P.S. I think I saw this int main()/void main() comment in the C++ Report magazine. Maybe it was a misprint.
Dire
P.S. I think I saw this int main()/void main() comment in the C++ Report magazine. Maybe it was a misprint.
Dire
[email=direwolf@digitalfiends.com]Dire Wolf[/email]
www.digitalfiends.com
www.digitalfiends.com
Windows doesn''t use the return value, so the returned value is pretty much for compatiblity''s sake... and no one uses DOS anymore...
/\ \/\/ /\ |< <-
/\ \/\/ /\ |< <-
/ // / |< <-
Here''s the whole blurb on main:
"5.1.2.2.1 Program startup
1 The function called at program startup is named main. The implementation declares no
prototype for this function. It shall be defined with a return type of int and with no
parameters:
int main(void) { /* ... */ }
or with two parameters (referred to here as argc and argv, though any names may be
used, as they are local to the function in which they are declared):
int main(int argc, char *argv[]) { /* ... */ }
or equivalent;9) or in some other implementation-defined manner."
(It then goes on to describe argc and argv.)
What this is saying, then, is that there are two, and only two definitions for main:
int main(void)
and
int main(int argc, char *argv[]) (or an equivalent such as char **argv)
"5.1.2.2.1 Program startup
1 The function called at program startup is named main. The implementation declares no
prototype for this function. It shall be defined with a return type of int and with no
parameters:
int main(void) { /* ... */ }
or with two parameters (referred to here as argc and argv, though any names may be
used, as they are local to the function in which they are declared):
int main(int argc, char *argv[]) { /* ... */ }
or equivalent;9) or in some other implementation-defined manner."
(It then goes on to describe argc and argv.)
What this is saying, then, is that there are two, and only two definitions for main:
int main(void)
and
int main(int argc, char *argv[]) (or an equivalent such as char **argv)
windows uses a return value.
You can look & see what it is!
The compiler annouces it to you whenever you''re debugging!
You can look & see what it is!
The compiler annouces it to you whenever you''re debugging!
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
Yes, Windows does use the return value from main(). It is the exit code of the thread. Its the same thing as calling ExitThread(retVal) (i.e. ExitThread(0));
[email=direwolf@digitalfiends.com]Dire Wolf[/email]
www.digitalfiends.com
www.digitalfiends.com
if you use a disassembler, you can see that when you return an int from main {or any other funtion, under the x86 machine) the return value is stored in the "eax" register. so obviously if you use void main("whatever") it won''t violate anything because the loader will just use whatever value is in the "eax" register. if the calling program or loader uses the return value from your program then use "int main();", else use "void main()". but this doesn''t violate anything. under MIPS machines it would use the "v0" register. i don''t know about other architectures, but i suspect that an "int" return value would use a register, thus it doesn''t matter if the return value isn''t important to the calling loader or program. if "void main()" violated anything, then i don''t think it would be allowed.
To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.
To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.
To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement