Variably modified array at file scope Variably modified array at file scope c c

Variably modified array at file scope


The reason for this warning is that const in c doesn't mean constant. It means "read only". So the value is stored at a memory address and could potentially be changed by machine code.


If you're going to use the preprocessor anyway, as per the other answers, then you can make the compiler determine the value of NUM_TYPES automagically:

#define NUM_TYPES (sizeof types / sizeof types[0])static int types[] = {   1,  2,   3,   4 };