Topic: Void main() -- 2 Return from `main
Author: JdeBP@jba.co.uk (Jonathan de Boyne Pollard)
Date: 1995/06/08 Raw View
James Kanze US/ESC 60/3/141 #40763 (kanze@lts.sel.alcatel.de) wrote:
: Implementation defined. What is or is not legal in language
: extensions can only be defined by the implementation.
Except, as I pointed out in my original post, the scope of paragraph 5 of
[basic.start.main] is not restricted to those definitions of `main' with
types listed by the standard.
It covers "a return statement in main" (c.f. paragraph 4, which covers
"calling exit() from main"), which to most people means "a return statement
in main, whatever the type of main is, whether it be one of the types listed
in the draft, that all implementations must support, or an additional type
allowed by the implementation".
If you look at the rewording that I proposed you will see the sort of
restriction on the applicability of implicit `return 0 ;' that I would
like to see here.
: In particular,
: concerning the point you raised (implicit return 0 at the end of
: main), I can see no sense in having an extension which cannot be used.
The point is that the draft doesn't make the distinction between the
"compulsory" types for `main' and the implementation-defined additions to the
set of allowable types. The implicit `return 0;' should be restricted to
either those types for main that return arithmetic types, or (better still)
to the two "compulsory" types, leaving the semantics of falling off the end
of `main' when `main' is defined with an implementation-defined type to the
implementation, where such semantics properly belong.
But I said all of this in the original message ...
Author: kanze@lts.sel.alcatel.de (James Kanze US/ESC 60/3/141 #40763)
Date: 1995/06/07 Raw View
In article <3r29f7$m11@silver.jba.co.uk> JdeBP@jba.co.uk (Jonathan de
Boyne Pollard) writes:
|> Second quibble with [basic.start.main] :
|> Assuming that the implementation accepts `void main()' as an additional
|> type for `main' (see another quibble for details on the "type" of main,
|> BTW) should the following program compile ?
|> void main() {}
Implementation defined. What is or is not legal in language
extensions can only be defined by the implementation. In particular,
concerning the point you raised (implicit return 0 at the end of
main), I can see no sense in having an extension which cannot be used.
I would therefor suppose that any implementation which did support
this extension would also *not* generate the implicit return 0.
--
James Kanze Tel.: (+33) 88 14 49 00 email: kanze@gabi-soft.fr
GABI Software, Sarl., 8 rue des Francs-Bourgeois, F-67000 Strasbourg, France
Conseils en informatique industrielle --
-- Beratung in industrieller Datenverarbeitung
Author: JdeBP@jba.co.uk (Jonathan de Boyne Pollard)
Date: 1995/06/06 Raw View
Second quibble with [basic.start.main] :
Assuming that the implementation accepts `void main()' as an additional
type for `main' (see another quibble for details on the "type" of main,
BTW) should the following program compile ?
void main() {}
It's not as easy as it looks, surprisingly. The answer, according to my
reading of the draft at any rate, is that is should *not*.
Why ?
Because, by my reading of [basic.start.main], paragraph 5, there is an
implicit `return 0;' inserted into that program, because there is no
explicit return statement. This yields :
void main() { return 0 ; }
which (according to [stmt.return] paragraph 2) is incorrect.
The flaw is obviously in [basic.start.main] paragraph 5. Rather than
make exceptions in the semantics of the return statement for the
distinguished function `main' (which *is* one option here), it is surely
better to keep the behaviour of `main' as close to the behaviour of all
other functions as possible.
So it is better to reword paragraph 5 of [basic.start.main] to say that
`return 0 ;' is only implied in the case where `main' is declared as
returning an arithmetic type (or even be more restrictive and say that it
is only defined for `int main()' and `int main(int, char**)') and that
otherwise falling off the end of `main' is implementation defined.
This has the additional benefit of allowing the implementation to define
the behaviour of
void main() {}
and even
struct __implementation_defined * main () {}
to be the same as that of
int main() {}
if it so wishes, or even different, if it so wishes.