Vincent Lefevre <[EMAIL PROTECTED]> writes: > On 2005-04-26 13:15:43 -0700, Zack Weinberg wrote: >> The initializer thus tries to give a variable with type unsigned:8 >> a value that it cannot hold. The diagnostic is correct. > > However it is correct to store any integer to an unsigned variable, > even if the original value cannot be represented.
If that operation occurs at runtime it has a well-defined result. If that operation occurs at compile time, as part of an initializer expression, the overflow must be diagnosed (C99 6.6p4 - constraint violation). Your request for a way to turn off the diagnostic is reasonable; you could make it happen sooner by helping out with DJ's fine-grained warning control project. > Therefore the diagnostic isn't necessary, and IMHO, there should be > a way to disable it (possibly locally to some part of the program). > >> Bruce Lilly <[EMAIL PROTECTED]> writes: >> > static const unsigned char AAA = 0x1U; >> > static const unsigned char BBB = 0x2U; >> >> Again, C does not work the way you think. These are not constants. > > But if they are never modified, they evaluate to constants, right? The compiler is allowed, but not required, to replace references to them with their known values. > The fact that they are not considered as constant expressions, > is it due to the fact that the environment is allowed to modify > them? No (and in fact the environment is not allowed to do that). It is because the set of things that are allowed in constant expressions are explicitly listed in C99 6.6, and read-only variables aren't one of the things on the list. zw