Suppressing the warning: "variably modified '<variable>' at file scope" generated due to floating-point computation in an integer expression

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

 

Such code is compiled without any warning by Microsoft Visual C++ (from as
far back as MSVC++ 2008).

 

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).

 

Other than the above warning, the resulting executable works as expected. In
particular, the size of state is correct in all cases.

 

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?

 

Thanks,

 

Beni Falk

 




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux