Re: help w/ c/c++ problem



Mark McIntyre wrote:
On Sun, 01 Jul 2007 18:52:52 +0200, in comp.lang.c , Harald van D?k
<truedfx@xxxxxxxxx> wrote:

Mark McIntyre wrote:
Then I'm afraid that both your book and your teacher are wrong. The C
Standard REQUIRES main to return an int.

This is incorrect.

I should have added "for a hosted implementation".

Then it is still incorrect.

The C standard requires implementations to accept main
returning int, but does not prohibit other return types either from being
allowed by implementations or from being used by programs.

This has been done to death. For a hosted implementation, your
statement is incorrect if you want to be compliant to the standard.

5.1.2.2.1 Program startup
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.

"Or in some other implementation-defined manner" means if the implementation
documents other types for main, and you use one of these other types, the
behaviour is not undefined. If you believe the behaviour is undefined,
please list any part of the standard that is violated by

void main(void) {}

There's of course nothing stopping your implementation returning
whatever it likes, including all your post marked "undeliverable".
However it would then not be a C compiler.
.



Relevant Pages

  • Re: help w/ c/c++ problem
    ... Standard REQUIRES main to return an int. ... statement is incorrect if you want to be compliant to the standard. ... "Debugging is twice as hard as writing the code in the first place. ...
    (comp.lang.c)
  • Re: help w/ c/c++ problem
    ... Standard REQUIRES main to return an int. ... Then it is still incorrect. ... "Or in some other implementation-defined manner" means if the implementation ...
    (comp.lang.c)
  • Re: help w/ c/c++ problem
    ... Standard REQUIRES main to return an int. ... Then it is still incorrect. ... These types might not include a return type of int. ... to the host environment is unspecified. ...
    (comp.lang.c)
  • Re: Really **wonderful** website for C interview questions!!!!!
    ... answers for interviews. ... that have incorrect answers and use those questions. ... >int main ... Even you mentioned some local standard not even an ISO-C standard. ...
    (comp.lang.c)
  • Re: why linker complains undefined reference to `main?
    ... >int main ... The function called at program startup is named main. ... implementation declares no prototype for this function. ... >blessed by the C standard. ...
    (comp.os.linux.development.apps)