This is the mail archive of the gcc@gcc.gnu.org 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


Vincent Lefevre 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.

It's legal.  That's why we compile it and don't issue an error.

 > Therefore the diagnostic isn't necessary,

Warnings are to help the programmer see where there is some code that,
although not necessarily an error, may require some attention.  This
is a classic case of such a warning.  This warning really does
indicate to the programmer that there might be a real problem.

 > and IMHO, there should be a way to disable it (possibly locally to
 > some part of the program).

Why not just fix the code?

 > > Bruce Lilly <blilly@erols.com> 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 fact that they are not considered as constant expressions,
 > is it due to the fact that the environment is allowed to modify
 > them?

It's due to what the C standard says.  A const variable in C isn't a
constant, it's just a read-only variable.

Andrew.


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