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]

Patch for making USHRT_MAX of type unsigned int



Hello,

  According to ANSI C standard, compiler defines type of decimal
constant without suffix searching appropriate type in the following
order:
       int
       long int
       long int int

  What type will integer constant 65535 have on a 16-bit machine with
short int and int are represented by 2 byte integer and long int is
represented by 4 byte integer?  It will be long int.  In this case we
have

sizeof (USHRT_MAX) == sizeof (long) == 4
sizeof (USHRT_MAX) > sizeof (UINT_MAX)

which is not what the most users expect.  The following patch solves
the problem.  The unsigned suffix for the UCHAR_MAX, CHAR_MAX is added
for uniformity.

  Actually, I did not find that sizeof (USHRT_MAX) > sizeof (UINT_MAX)
contradicts to the standard.  Therefore I am asking the approval to
commit the patch or waiting for any comment.

Vladimir Makarov.

2001-06-25  Vladimir Makarov  <vmakarov@toke.toronto.redhat.com>

	* glimits.h (UCHAR_MAX, CHAR_MAX, USHRT_MAX): Use unsigned suffix.


Index: glimits.h
===================================================================
RCS file: /cvs/gcc/egcs/gcc/glimits.h,v
retrieving revision 1.10
diff -c -p -r1.10 glimits.h
*** glimits.h	2000/07/21 00:47:27	1.10
--- glimits.h	2001/06/25 20:26:21
***************
*** 22,35 ****
  
  /* Maximum value an `unsigned char' can hold.  (Minimum is 0).  */
  #undef UCHAR_MAX
! #define UCHAR_MAX 255
  
  /* Minimum and maximum values a `char' can hold.  */
  #ifdef __CHAR_UNSIGNED__
  #undef CHAR_MIN
  #define CHAR_MIN 0
  #undef CHAR_MAX
! #define CHAR_MAX 255
  #else
  #undef CHAR_MIN
  #define CHAR_MIN (-128)
--- 22,35 ----
  
  /* Maximum value an `unsigned char' can hold.  (Minimum is 0).  */
  #undef UCHAR_MAX
! #define UCHAR_MAX 255U
  
  /* Minimum and maximum values a `char' can hold.  */
  #ifdef __CHAR_UNSIGNED__
  #undef CHAR_MIN
  #define CHAR_MIN 0
  #undef CHAR_MAX
! #define CHAR_MAX 255U
  #else
  #undef CHAR_MIN
  #define CHAR_MIN (-128)
***************
*** 46,52 ****
  
  /* Maximum value an `unsigned short int' can hold.  (Minimum is 0).  */
  #undef USHRT_MAX
! #define USHRT_MAX 65535
  
  /* Minimum and maximum values a `signed int' can hold.  */
  #ifndef __INT_MAX__
--- 46,52 ----
  
  /* Maximum value an `unsigned short int' can hold.  (Minimum is 0).  */
  #undef USHRT_MAX
! #define USHRT_MAX 65535U
  
  /* Minimum and maximum values a `signed int' can hold.  */
  #ifndef __INT_MAX__


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