So, which year of the standard is that?
This is a discussion on int main vs void main within the C Programming forums, part of the General Programming Boards category; So, which year of the standard is that?...
So, which year of the standard is that?
For information on how to enable C++11 on your compiler, look here.
よく聞くがいい!私は天才だからね! ^_^
C99, huh? I stand corrected.
And yet, they made an exception to make the standard utterly and completely useless for embedded systems that match that criteria. Well done.
For information on how to enable C++11 on your compiler, look here.
よく聞くがいい!私は天才だからね! ^_^
From the C++ 0x draft standard.
Jim3.6
Start and termination
3.6.1
1
Main function
[basic.start]
[basic.start.main]
A program shall contain a global function called main, which is the designated start of the program. It
is implementation-defined whether a program in a freestanding environment is required to define a main
function. [ Note: In a freestanding environment, start-up and termination is implementation-defined; start-
up contains the execution of constructors for objects of namespace scope with static storage duration;
termination contains the execution of destructors for objects with static storage duration. — end note ]
It's not a choice. The correct forms of main are either...
orCode:int main (void) { return errorlevel; // usually 0 }
Although it's apparently not taught in class... the operating system actually does make use of the return value of main() ... It's used in batch files and shell scripts, it's used when one program launches a child program and so on.Code:int main (int argc, char *argv[]) { return errorlevel; //usually 0 }
If you use void main() and do not return a value, the address reserved for the return value is uninitialized, basicially containing a random number, and can cause wild misbehaviors in cases where a return value is expected.
LOL - "ruin" - fantastic typo - and yet so apt.
> It's used in batch files and shell scripts, it's used when one program launches a child program and so on.
Yes indeed.
Long ago, I found a fantastic little utility for a job I was doing that was rendered almost completely useless because the exit status was garbage.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
I support http://www.ukip.org/ as the first necessary step to a free Europe.