3

The C Language doesn't support function overloading [1] because there is no name mangling in C.

But C allows one to write both

int main ()

and

int main ( int argc, char** argv )

When defining the main function. Isn't this function overloading?

Community
  • 1
  • 1
singingsingh
  • 1,364
  • 14
  • 15
  • 2
    I'm guessing the first declaration should be `int main()` or `int main(void)`? – Chris Hayes May 16 '14 at 06:28
  • I suppose you meant `int main()` rather than `int main` to think that it is function overloading? `int main;` is variable and not function. – Prabhu May 16 '14 at 06:30
  • The C standard says that the implementation doesn't declare any prototype for `main`, and that it shall be defined with a return type of `int` and no arguments (`int main(void) {}`) **or** two arguments (`int main(int argc, char *argv[]) {}`) (or in some other implementation-defined manner). Whichever form you pick, it will be _the_ `main` of your program. For your reference, this is described in section 5.1.2.2.1 ("Program startup"). – Michael May 16 '14 at 06:37

2 Answers2

4

This is not overloading, because you can't have both a no-arg main and a 2-arg main in the same program. Overloading main would require there to be two versions of main in the same program with different signatures, where which one is executed would be determined... somehow.

user2357112
  • 260,549
  • 28
  • 431
  • 505
1

No, this is not function overloading, as the first declaration declares a variable while the second declaration declares a function.

Codor
  • 17,447
  • 9
  • 29
  • 56