Mail Archives: djgpp/1999/10/17/15:15:58
Rodeo Red <rodeored AT netstep DOT net> schrieb in im Newsbeitrag:
84EFC73E5BDD300C DOT 85A7FCC32BD1270B DOT F7CB654E8161FA9A AT lp DOT airnews DOT net...
(...)
> This command line:
>
> gcc -c -Wall hello.cpp
>
> is supposed to produce the object file hello.o, but doesn't . Instead I
> get this message:
> hello.cpp:4: return type for `main' changed to `int'
>
> What does this mean ?
>
>
> here is hello.cpp:
>
> #include <iostream.h>
>
> void main ()
> {
> cout <<"Hello world!\n";
> }
>
(...)
I tried to compile the program you provided, with the switches you told (vers. 2.95).
Here is what I got:
>gcc -c -Wall hello.cpp
hello.cpp:4: warning: return type for `main' changed to `int'
gcc simply omits a warning, since you told it to provide (mostly) all warnings, but compiles
your file without problems!
As you may already know, it is in C allowed but not recommend to alter the return type of "main"
(since then the return-value is unspecified).
But is it for a cpp-program?
I searched a locale copy of an Ansi-C++ draft and here is what i found:
(...)
This function is not predefined by the implementation, it cannot be
overloaded, and its type is implementation-defined. All
implementations shall allow both of the following definitions of main:
int main() { /* ... */ }
and
int main(int argc, char* argv[]) { /* ... */ }
(...)
If control
reaches the end of main without encountering a return statement, the
effect is that of executing
return 0;
(...)
According to this, you were right to report this warning as an anomaly for a cpp-program.
Best Regards
Oliver Roese
- Raw text -