Thread: selection
View Single Post
Old 02-03-2003, 09:26 AM   PM User | #5
maes
Regular Coder

 
Join Date: Jul 2002
Location: Belgium
Posts: 124
Thanks: 0
Thanked 0 Times in 0 Posts
maes is an unknown quantity at this point
First of all sorry for the language, but it wasn't meant to be disrespectfull. I also have been corrected when I made a reply, and I felt that the person who corrected me was a , well you know. I didn't want him/her to feel the same way about me, that is why I said it. If you or him/her took it the wrong way, then I'm sorry, I apologize.


Second, using void main isn't right. Not because the compiler allows it, that doesn't mean it is right.
C99 standard:
Quote:
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.
I agree that it doesn't explicitly say: "you can not use void main()"
But "It shall be defined with a return type of int" is good enough for me.

From Bjarne Stroustrup:
Quote:
The definition
void main() { /* ... */ }

is not and never has been C++, nor has it even been C. See the ISO C++ standard 3.6.1[2] or the ISO C standard 5.1.2.2.1. A conforming implementation accepts
int main() { /* ... */ }

and
int main(int argc, char* argv[]) { /* ... */ }

A conforming implementation may provide more versions of main(), but they must all have return type int. The int returned by main() is a way for a program to return a value to "the system" that invokes it. On systems that doesn't provide such a facility the return value is ignored, but that doesn't make "void main()" legal C++ or legal C. Even if your compiler accepts "void main()" avoid it
__________________
If you don't succeed at first, redefine succes

Last edited by maes; 02-03-2003 at 09:56 AM..
maes is offline   Reply With Quote