This is the mail archive of the gcc-patches@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]

Re: Patch for making USHRT_MAX of type unsigned int


On 25 Jun 2001, Geoff Keating wrote:

> This patch is not quite right.
> 
> The C standard says that types such as USHRT_MAX should have type `as
> would an expression that is an object of the corresponding type
> converted according to the integer promotions'.

Yes.  Also, GCC doesn't yet implement the C99 integer constant type rules,
which are different from the C89 ones - but this is irrelevant when the
correct suffixes are used in <limits.h>.

> #if INT_MAX <= 65535
> #define USHRT_MAX 65535
> #else
> #define USHRT_MAX 65535U
> #endif

This is the wrong way round; it should be 65535U if int is small, 65535 in
the normal case.

> For UCHAR_MAX, it is always correct to just write
> 
> #define UCHAR_MAX 255
> 
> as 'int' must be at least 16 bits.

Of course, this is wrong where char and int are the same size >= 16 bits,
but glimits.h is currently unconditionally incorrect in this case.  The
simplified glimits.h I posted in the specs replacement thread should do
the job in all cases (including getting the correct types, as here) if the
compiler can be made to predefine the necessary macros in all cases.

-- 
Joseph S. Myers
jsm28@cam.ac.uk


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