As the error message indicates, main
expects char**
for its second argument. However, due to array decay rules, the following are both OK:
int main(int argc, char** argv); // OK
int main(int argc, char* argv[]); // OK
And, in fact, the following is also equivalent because array decay doesn't care about dimensions:
int main(int argc, char* argv[5]); // OK
However, whereas in C99 arrays may have variable length, this is not the case in C++. So using a non-constant expression for that array dimension — in your case, printf("Hello world\n")
— is invalid syntax.
int main(int argc, char* argv[printf("Hello, world!\n")]); // Not OK!
This invalid syntax is confusing the parser and causing this misleading error in your compiler.
If you simplify the code slightly to remove the function-call-expression (but still using a non-constant for array bounds) then you get a far more relevant error message:
int x = 5;
int main(int argc, char* argv[x]) {}
// error: array bound is not an integer constant
Actually, GCC 4.1.2 gives this useful message for your original code, too, so your compiler must be really old... either that or your testcase is broken despite the far newer GCC 4.5.1 yielding the message you posted.