9

C++ standard lists allowed forms of main. It doesn't list int main(void) as an allowed form. But, it generally states that

The parameter list (void) is equivalent to the empty parameter list

Is int main(void) an allowed form?

geza
  • 28,403
  • 6
  • 61
  • 135
  • [Probably yes?](https://stackoverflow.com/a/44859345/2752075) – HolyBlackCat Jul 01 '17 at 09:40
  • 10
    In C++ using an empty argument list is the same as using `void`. Both are equal and interchangeable. This is one of the *big* differences with C, where a function declared without any arguments (i..e empty set of parentheses `()`) can take any number of unspecified arguments. – Some programmer dude Jul 01 '17 at 09:41
  • @HolyBlackCat close as dupe perhaps? this is just a subset of that question – M.M Jul 02 '17 at 11:53

2 Answers2

10

From N3936 standard draft:

3.6 Start and termination

3.6.1 Main function

2 An implementation shall not predefine the main function. This function shall not be overloaded. It shall have a declared return type of type int, but otherwise its type is implementation-defined. An implementation shall allow both

a function of () returning int and

— a function of (int, pointer to pointer to char) returning int

as the type of main (8.3.5).

Then:

8.3.5 Functions

4 ... A parameter list consisting of a single unnamed parameter of non-dependent type void is equivalent to an empty parameter list. ...

Consequently,

int main(void)

is an allowed form of main function.

Edgar Rokjān
  • 17,245
  • 4
  • 40
  • 67
0

In addition to comment of @Some programmer dude and @Edgar's answer, this is the part of N3936 draft which explains given difference between C++ and standard C:

C.1.7 Clause 8: declarators [diff.decl]

8.3.5

Change: In C++, a function declared with an empty parameter list takes no arguments. In C, an empty parameter list means that the number and type of the function arguments are unknown.

Example:

int f(); // means int f(void) in C++
          // int f( unknown ) in C

Bojan Komazec
  • 9,216
  • 2
  • 41
  • 51