LWN.net Logo

Dennis Ritchie RIP your legacy...

Dennis Ritchie RIP your legacy...

Posted Oct 13, 2011 18:37 UTC (Thu) by HelloWorld (guest, #56129)
In reply to: Dennis Ritchie RIP your legacy... by jengelh
Parent article: Dennis Ritchie RIP

Why? int main() is fine in C99 (and it even says to in those slides).


(Log in to post comments)

Dennis Ritchie RIP your legacy...

Posted Oct 14, 2011 1:55 UTC (Fri) by galanom (guest, #80787) [Link]

It is illegal in C11 however.

Dennis Ritchie RIP your legacy...

Posted Oct 14, 2011 3:28 UTC (Fri) by HelloWorld (guest, #56129) [Link]

> It is illegal in C11 however.
No it's not, at least not in the current draft. Section 6.7.6.3, paragraph 14:

"An empty list in a function declarator that is part of a definition of that function specifies that the function has no parameters."

Dennis Ritchie RIP your legacy...

Posted Oct 14, 2011 21:45 UTC (Fri) by jengelh (subscriber, #33263) [Link]

IIRC, the standard demanded that main be one of two signatures: int main(void) or int main(int, char **) only. That would be in line with page 24's "you should use int main(void) - because the standard says so", provided the PDF is right.

Dennis Ritchie RIP your legacy...

Posted Oct 17, 2011 11:50 UTC (Mon) by jwakely (subscriber, #60262) [Link]

An empty list in a function declarator that is part of a definition of that function specifies that the function has no parameters.
i.e. In a function definition (as opposed to a prototype) int main() is the same as int main(void) and so is correct.

Dennis Ritchie RIP your legacy...

Posted Oct 14, 2011 16:32 UTC (Fri) by tjc (subscriber, #137) [Link]

On a more pragmatic level, gcc -Wall doesn't complain about main(). If it's good enough for -Wall, then it's good enough for me. ;)

Dennis Ritchie RIP your legacy...

Posted Oct 14, 2011 16:41 UTC (Fri) by HelloWorld (guest, #56129) [Link]

I disagree. I think that -Wall should print many more warnings than it does.

Dennis Ritchie RIP your legacy...

Posted Oct 15, 2011 11:37 UTC (Sat) by da4089 (subscriber, #1195) [Link]

+1 -Wextra

Copyright © 2013, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds