This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: New gcc 4.0.0 warnings seem spurious

Bruce Lilly <> writes:

>> I don't see why you think the warnings are spurious.  ~(AAA), for example, 
>> is 4294967294,
> No, in this context it is 254 (an 8-bit unsigned field with the LSB clear).

C does not work the way you think.  AAA has type unsigned int.  The
expression ~(AAA) also has type unsigned int, and the value that
Joseph stated.  It always has that type and value, no matter what
context it appears in.  The initializer thus tries to give a variable
with type unsigned:8 a value that it cannot hold.  The diagnostic is

> 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.
They are variables, which happen to be read-only.  You cannot use them
in initializers, just as you cannot use any other variable in an

Furthermore, with that definition, AAA has type unsigned char, but
~(AAA) has type *signed* int and the value -2, because all arithmetic
operations on types smaller than int, signed or unsigned, are first
promoted to int (this is a slight simplification but is correct as far
as it goes).


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]