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]

Re: Patch: Re: glimits.h is not compatible with -traditional

> > > +#ifdef __STDC__
> > >  #define UINT_MAX (INT_MAX * 2U + 1)
> > > +#else
> > > +#define UINT_MAX ((unsigned)INT_MAX * 2 + 1)
> > > +#endif
> I think you'll just have to ignore this warning.  There is no
> correct solution, as far as I can see.

I did some more testing.  The current header works because `gcc -traditional'
doesn't reject the `U' suffix, or even warn about it.  The warning only
appears if `-traditional' isn't specified.

I am not concerned about the warning itself, although it is bogus if
the define is wrapped in a `#ifdef __STDC__'.

As I understand it, there is no way to define unsigned constants that
are usable in cpp expressions under traditional C when faced with the
2's compliment limit (ie, all comparisons in cpp expressions are signed).
The above macro evaluates to the correct unsigned value but can't be used
in cpp expressions because it is not a valid cpp constant.

HP-UX 10.20 defines UINT_MAX and ULONG_MAX to be 4294967295.  Ultrix 4.3
defines them as ((unsigned)4294967295).  Both of these are obviously
for 32 bit machines.  The ultrix definition has the same problem as
the one above.  The unsigned cast could be removed as in the HP define.
For example,

#define UINT_MAX (INT_MAX * 2 + 1)
#define ULONG_MAX (LONG_MAX * 2 + 1)

On machines where int and long are the same, both are equivalent to -1
and only equality comparisons work.  On 64 bit machines, this only applies
to ULONG_MAX. Within C itself, the `U' defines need a cast.  Is this the
traditional approach?

J. David Anglin                        
National Research Council of Canada              (613) 990-0752 (FAX: 952-6605)

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