Ever look at old code and think? What the hell was I smoking?

Pages: 1... 345
NoXzema wrote:
I claimed that C89 and C90 (which are essentially the same thing), allowed "void main" only by the fact that it does not have anything stating that it's not allowed. I'm not saying it's the most correct, I'm not saying it should be allowed, only that in C89/C90, it was not illegal to have a main function that had no return value.


I'd actually say that it was an oversight and really wasn't allowed and is the reason they added the rule of it being defined with a return type of int because they didn't like people using void main.

I also take what Bjarne says as fact because of two reasons. 1) He would have had to talk to Dennis Ritchie while developing C++ to make sure the rules were upheld (and again it helped that they were friends and co-workers). 2) I spent the day discussing it with him via email. ( http://prntscr.com/31tp7o )

Two excerpts from those emails:

Bjarne wrote:

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


It seems clear to me and it reflects what has been the case since the days of Dennis Ritchie (before the C89 standard, I simply looked in K&R and/or asked him).


Bjarne wrote:

Back in the 1980s the programming world was less legalistic. If someone genuinely wanted to know, they could have asked the committee or DMR is it was an oversight. I did ask DMR (about many things). Compilers don't settle such issues because as soon as one compiler have had a bug, it - and its - competitors - maintain compatibility flags forever. There exists modern C++ compilers with -ARM flags for compatibility with all the bugs I had in 1989 :-(


So basically, the omission was accidental and the use of void main is what made them tweak it to add that it must be int.
Topic archived. No new replies allowed.
Pages: 1... 345