Cygwin GCC (4.8.3, 4.9.2) complains about the following code:
unsigned char array[ (unsigned short)((80.0f)/(5.0f)) ];
saying:
ModifiedVariably.c:3:1: error: variably modified 'array' at file scope [-Werror]
unsigned char array[ (unsigned short)((80.0f)/(5.0f)) ];
^
But there isn't any variable, and the result of the floating point calculation is cast to an unsigned before being used as a subscript.
Why are we getting this error, and how (besides not using floating point constants) can it be resolved?
I know that similar questions have been asked before, but as far as I could find out, these involved actually using variables as index, at file scope.
It appears that other compilers (e.g., Visual Studio and the TASKING toolchain) do not have this problem.
P.S.: The actual code has a number of #define
's; I took the resulting preprocessor output for simplicity.