Patch -Wtraditional, warn about `U' integer constant suffix

Kaveh R. Ghazi
Mon Aug 7 13:27:00 GMT 2000

 > From: Michael Meissner <>
 > > 
 > > Hmm, I've come across a problem in practice with this.  I'd like to
 > > solicit opinions on how to proceed.
 > > 
 > > Suppose you have the following code:
 > > 
 > >  > #include <limits.h>
 > >  > unsigned int i = UINT_MAX;
 > > 
 > > and suppose that your system is a modern one supporting U so limits.h
 > > defines UINT_MAX to 4294967295U.  Now you are hosed, there is no way
 > > to silence the warning.  Even though UINT_MAX is defined in a system
 > > header, the use of it occurs in user code so the warning will appear.
 > > Ditto for uses in cpp #if conditionals.
 > > 
 > > Any suggestions on how to avoid this problem?
 > I don't believe the traditional limits.h had UINT_MAX, so a
 > traditional program shouldn't be refering to it.

Programs intended to run on traditional C frequently refer to
UINT_MAX.  Currently gcc does, so does gettext which gcc uses.
Perhaps this expanded code fragment will make clear how this happens
in practice.

 > #ifdef HAVE_LIMITS_H
 > #include <limits.h>
 > #endif
 > #ifndef UINT_MAX
 > #define UINT_MAX <some expression to calculate it without using U>
 > #endif
 > unsigned int i = UINT_MAX;

Although the backup definition of UINT_MAX often uses "sizeof" as part
of the expression thus making it no longer suitable for #if
conditionals, the example as I have written it is pretty common.

The problem again is that on modern systems which *do* have UINT_MAX
in limits.h, they use `U' and there's no way to avoid the warning when
one adds -Wtraditional.

I hate adding new warnings if there's no way to silence it in
legitimate code. :-(

Kaveh R. Ghazi			Engagement Manager / Project Services		Qwest Internet Solutions

More information about the Gcc-patches mailing list