1

The C99 standard document I have clearly states that

6.7.5.3.14 An identifier list declares only the identifiers of the parameters of the function. An empty list in a function declarator that is part of a definition of that function specifies that the function has no parameters. The empty list in a function declarator that is not part of a definition of that function specifies that no information about the number or types of the parameters is supplied.

What I interpret from that sentence is that writing void in function definition is redundant. Did I get it correctly?

Yu Hao
  • 119,891
  • 44
  • 235
  • 294
  • `main()` is a special case, [see here](http://stackoverflow.com/questions/29190986/is-int-main-without-void-valid-and-portable-in-iso-c) for discussion specific to `main` – M.M Jun 25 '15 at 22:15

1 Answers1

5

No, you're slightly wrong.

  • void specifies that there is abosolutely no arguments passed.
  • empty parenthesis () indicates that the function can be called with any number of arguments, without generating a warning.

Note: Remember, there is no prototype defined or supplied by the implementation for main().

Maybe, C11 standard, chapter 5.1.2.2.1, describes it better way,

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;10) or in some other implementation-defined manner.

Sourav Ghosh
  • 133,132
  • 16
  • 183
  • 261
  • The prototype bit is the important part here. If there is a function prototype (a.k.a. a function declarator that is not a part of a function definition) preceding the function definition as in `int main(void); int main() { ... }`, then obviously C99 6.7.5.3p14 (or the equivalent C11 6.7.6.3p14) would be applicable. –  May 15 '15 at 07:09