I have some code like this:
static int a = 6;
static int b = 3;
static int Hello[a][b] =
{
{ 1,2,3},
{ 1,2,3},
{ 1,2,3},
{ 1,2,3},
{ 1,2,3},
{ 1,2,3}
};
But when I compile it, it says error:
variably modified 'Hello' at file scope
How could this happen? And how could I fix it?
You can not have a static array whose size is given as a variable.
That's why constants should be #define
d:
#define a 6
This way, the preprocessor will replace a
with 6
, making it a valid declaration.