2

Is there a limit for the number of parameters main can have?

Here is a sample code which runs perfectly … and I am not aware if it is allowed.

int main( char* argv[], int argc, int arv, bool test)
{
    cout<<"Hello"<<endl;
}

Output: Hello

I am using

  • gcc-4.1.2_20070115-0.32.53

  • gcc-c++-4.1.2_20070115-0.32.53

  • libgcc-4.1.2_20070115-0.32.53

  • gcc-objc-4.1.2_20070115-0.32.53

Konrad Rudolph
  • 530,221
  • 131
  • 937
  • 1,214
samairtimer
  • 826
  • 2
  • 12
  • 28

1 Answers1

6

The C++ standard does not explicitly forbid these signatures, but it does not require them to work either. All it says is that the two following signatures must work on any compiler:

  • int main()
  • int main(int, char**)

And that the return type must be int.

Community
  • 1
  • 1
Konrad Rudolph
  • 530,221
  • 131
  • 937
  • 1,214
  • That is wrong. Please look at freestanding implementations. – Deduplicator Apr 23 '14 at 13:50
  • 1
    @Deduplicator How can it be wrong when it comes directly from the standard? Freestanding implementations have their own little niche, but people (and the standard, unless noted otherwise) talk about hosted implementations. My answer simply doesn’t apply to freestanding implementations, which don’t have a defined startup sequence at all. – Konrad Rudolph Apr 23 '14 at 16:25
  • Just say it only applies to hosted implementations/not to freestanding implementations, and it's ok. Yes, people mostly ask about hosted, but they still also programm the bare metal. – Deduplicator Apr 23 '14 at 16:26