On Jun 20, 5:06 am, Jack Klein <jackkl...@spamcop.net> wrote:
> On Thu, 19 Jun 2008 12:42:00 -0700 (PDT), acehr...@gmail.com
> wrote in comp.lang.c++:
> [snip]
> > No, 'void main' was not always illegal; the early C
> > specification did not spell out what main's return type
> > would be.
> You are quite wrong about that. The earliest C specification
> was K&R, and it used implicit int as the return type for
> main(). And "void main()" was illegal at the time, BECAUSE
> THE KEYWORD 'void' DID NOT EXIST IN THE C LANGUAGE AT THE
> TIME. (sorry for shouting).
> The keyword 'void' was added to the C language by the original
> 1989/1990 ANSI and ISO standards.
The keyword void was added to the C language sometime before the
ANSI and the ISO standard was adopted.
> These are the same standards that clearly stated:
> "The function called at program startup is named main. The
> implementation declares no prototype for this function. It can be
> defined 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[]) { /*... */ }"
> So, yes, void main() has always been invalid C.
Unportable. The C standard makes it clear that there can be
other definitions of main as well; C99 makes it absolutely clear
that an implementation is allowed to accept void as well. It
wasn't really clear in C90, and the C++ standard clarified it in
the opposite direction, requiring a diagnostic if the return
type isn't int.
> On the other hand, compiler vendors are allowed to add any
> extensions they wish to their compilers, as long as those
> extensions don't change the meaning of a conforming program.
And that they diagnose all errors which require a diagnostic.
> Since void main() produces undefined behavior, a program that
> uses it is not conforming, allowing a compiler to accept it as
> a non-standard extension.
In this case, the C standard explicitly states that an
implementation can provide additional forms.
Historically, of course, all of the Unix implementations of C
(and they were the first) accepted a form with three parameters
as well, so the C standard wasn't innovating in allowing this.
--
James Kanze (GABI Software) email:
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34