On Fri, Dec 20, 2024 at 01:46:25PM +0200, beni.falk--- via Gcc-help wrote: > Hi, > > I would like to write C code such as the following: > > #define X_MIN -7.5 > #define X_MAX 12.7 > #define X_STEP 0.1 > > #define NPOINTS ((unsigned) (X_MAX - X_MIN) / X_STEP)) > > static int state[NPOINTS]; > > However, it generates a compiler warning as follows: > > variably modified 'state' at file scope When you use a macro, you should always almost parenthesise it, like #define NPOINTS ((unsigned) ((X_MAX) - (X_MIN)) / (X_STEP))) Macro text replacement is textual. And your floating point math is almost certainly not what you want like this. Most machines use binary floating point, which gives you ronding errors here, and conversion from float to integer is truncation, likely not what you intended. > The above warning is correct, as far as C language definition is concerned > (any floating-point constants participating in an integer expression must be > immediate operands of casts). Huh? > I am used to being able to suppress any kind of GCC compiler warning by > using an appropriate compiler option of pragma. How can the above warning be > suppressed? By writing better code? :-) Less fragile, etc. Segher