Consider this code:
enum
{
ERR_START,
ERR_CANNOTOPENFILE,
ERR_CANNOTCONNECT,
ERR_CANNOTCONNECTWITH,
ERR_CANNOTGETHOSTNAME,
ERR_CANNOTSEND,
};
char* ERR_MESSAGE[] =
{
[ERR_START] = "Nothing",
[ERR_CANNOTOPENFILE] = "Cannot open '%s' filename.\n",
[ERR_CANNOTCONNECT] = "Cannot connect.\n",
[ERR_CANNOTCONNECTWITH] = "Cannot connect with '%s'.\n",
[ERR_CANNOTGETHOSTNAME] = "Cannot get host name.\n",
[ERR_CANNOTSEND] = "Cannot send.\n",
};
Given this erros:
error.h:27:1: error: parameter ‘ERR_MESSAGE’ is initialized
error.h:29:2: error: array index in non-array initializer
error.h:29:2: error: (near initialization for ‘ERR_MESSAGE’)
error.h:29:2: warning: initialization from incompatible pointer type
error.h:30:2: error: array index in non-array initializer
[....]
I’m compiling with -std=c99.
How to fix this?
I think you are getting this message because another syntax error in the file (or something included before it). I pasted the code into a standalone C file and got no compile errors with
gcc -std=c99 -c test.cand my GCC version is gcc (GCC) 4.6.3 20120306 (Red Hat 4.6.3-2).A likely error (maybe the only one) is if there’s a function declaration that is missing a semicolon. With the code
I get the similar errors