Topic: Beginer help Void main()
Author: maxtal@Physics.usyd.edu.au (John Max Skaller)
Date: 1995/06/07 Raw View
In article <3qv7mr$nnq@engnews2.Eng.Sun.COM>,
Steve Clamage <clamage@Eng.Sun.COM> wrote:
>In article F3@netcom.com, danryoku@netcom.com (Scott Wang) writes:
>>I just started C++ and have a question. This may be stupid but here it
>>goes. What is the difference between the line "void main()" and "main
>>()"? What does the void do.
>
>According to the language definition, main() returns an int value to
>the environment which invokes the program. Thus, conforming code
>must declare main to return an int.
>
>Some implementations, as an extension, allow you to declare main
>to return nothing (void). Such code is not portable and will not
>compile on all systems, since it violates the language definition.
This is not my understanding.
int main();
int main(int, char *argv[]);
must be supported by conforming processors, other types can
be supported by the implementor -- these extra types if appropriately
documented are NOT extensions but part of the implementation
defined component of the Standard.
While this is a "legalistic" interpretation I'd like to point
out that there is no guarrantee that the following code must
be accepted by a conformaing processor:
int main() {
int my_initialisation_counter = 1;
return 0;
}
The program could be too long. The variable name could be too long.
It's implementation defined whether this is the case or not.
(this is a change from C)
--
JOHN (MAX) SKALLER, INTERNET:maxtal@suphys.physics.su.oz.au
Maxtal Pty Ltd,
81A Glebe Point Rd, GLEBE Mem: SA IT/9/22,SC22/WG21
NSW 2037, AUSTRALIA Phone: 61-2-566-2189
Author: danryoku@netcom.com (Scott Wang)
Date: 1995/06/05 Raw View
I just started C++ and have a question. This may be stupid but here it
goes. What is the difference between the line "void main()" and "main
()"? What does the void do. I don't understand. Please mail me if you
have an answer.
danryoku@netcom.com (Scott Wang)
Author: clamage@Eng.Sun.COM (Steve Clamage)
Date: 1995/06/05 Raw View
In article F3@netcom.com, danryoku@netcom.com (Scott Wang) writes:
>I just started C++ and have a question. This may be stupid but here it
>goes. What is the difference between the line "void main()" and "main
>()"? What does the void do.
According to the language definition, main() returns an int value to
the environment which invokes the program. Thus, conforming code
must declare main to return an int.
Some implementations, as an extension, allow you to declare main
to return nothing (void). Such code is not portable and will not
compile on all systems, since it violates the language definition.
---
Steve Clamage, stephen.clamage@eng.sun.com