This is the mail archive of the cygwin-patches mailing list for the Cygwin 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]

[PATCH] Fix type inconsistencies in stdint.h


    Hi team,

  Upstream GCC just gained the ability to know all about the stdint.h types
and limits internally.  If you're interested in the background, see

    http://gcc.gnu.org/ml/gcc/2009-04/msg00000.html

and thread for further reading.

  I've submitted the necessary info for the cygwin GCC backend, and now the
associated testcases show up a few bugs in our stdint.h declarations.
Basically:-

- uint32_t is "unsigned int", but UINT32_MAX is an unsigned long int constant
(denoted by the 'UL' suffix).
- int_least32_t is "long", where INT_LEAST32_MIN and INT_LEAST32_MAX are plain
(unsuffixed) int constants.
- int_fast16_t and int_fast32_t are both "long", where INT_FAST16/32_MIN/MAX
are all plain (unsuffixed) ints.
- intptr_t is "long" but INTPTR_MIN and INTPTR_MAX lack the "L" suffix and so
are just ints.
- size_t is "unsigned int" but the SIZE_MAX constant is unsigned long.

  This is bad because if the value of one of these MIN or MAX limits is not of
the correct integer type matching the integer type it is used in conjunction
with, there will be an implicit cast operation anytime you assign the
wrongly-typed value to a variable of the type for which it is supposed to be
the limit.

  The attached patch fixes all these by adjusting only the suffix letters.  OK
for head?

winsup/cygwin/ChangeLog

	* include/stdint.h (UINT32_MAX, INT_LEAST32_MIN, INT_LEAST32_MAX,
	INT_FAST16_MIN, INT_FAST32_MIN, INT_FAST16_MAX, INT_FAST32_MAX,
	INTPTR_MIN, INTPTR_MAX, SIZE_MAX):  Fix integer constant suffixes.

    cheers,
      DaveK
Index: winsup/cygwin/include/stdint.h
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/include/stdint.h,v
retrieving revision 1.10
diff -p -u -r1.10 stdint.h
--- winsup/cygwin/include/stdint.h	17 May 2008 21:34:05 -0000	1.10
+++ winsup/cygwin/include/stdint.h	3 Apr 2009 23:07:50 -0000
@@ -80,19 +80,19 @@ typedef unsigned long long uintmax_t;
 
 #define UINT8_MAX (255)
 #define UINT16_MAX (65535)
-#define UINT32_MAX (4294967295UL)
+#define UINT32_MAX (4294967295U)
 #define UINT64_MAX (18446744073709551615ULL)
 
 /* Limits of minimum-width integer types */
 
 #define INT_LEAST8_MIN (-128)
 #define INT_LEAST16_MIN (-32768)
-#define INT_LEAST32_MIN (-2147483647 - 1)
+#define INT_LEAST32_MIN (-2147483647L - 1L)
 #define INT_LEAST64_MIN (-9223372036854775807LL - 1LL)
 
 #define INT_LEAST8_MAX (127)
 #define INT_LEAST16_MAX (32767)
-#define INT_LEAST32_MAX (2147483647)
+#define INT_LEAST32_MAX (2147483647L)
 #define INT_LEAST64_MAX (9223372036854775807LL)
 
 #define UINT_LEAST8_MAX (255)
@@ -103,13 +103,13 @@ typedef unsigned long long uintmax_t;
 /* Limits of fastest minimum-width integer types */
 
 #define INT_FAST8_MIN (-128)
-#define INT_FAST16_MIN (-2147483647 - 1)
-#define INT_FAST32_MIN (-2147483647 - 1)
+#define INT_FAST16_MIN (-2147483647L - 1L)
+#define INT_FAST32_MIN (-2147483647L - 1L)
 #define INT_FAST64_MIN (-9223372036854775807LL - 1LL)
 
 #define INT_FAST8_MAX (127)
-#define INT_FAST16_MAX (2147483647)
-#define INT_FAST32_MAX (2147483647)
+#define INT_FAST16_MAX (2147483647L)
+#define INT_FAST32_MAX (2147483647L)
 #define INT_FAST64_MAX (9223372036854775807LL)
 
 #define UINT_FAST8_MAX (255)
@@ -119,8 +119,8 @@ typedef unsigned long long uintmax_t;
 
 /* Limits of integer types capable of holding object pointers */
 
-#define INTPTR_MIN (-2147483647 - 1)
-#define INTPTR_MAX (2147483647)
+#define INTPTR_MIN (-2147483647L - 1L)
+#define INTPTR_MAX (2147483647L)
 #define UINTPTR_MAX (4294967295UL)
 
 /* Limits of greatest-width integer types */
@@ -144,7 +144,7 @@ typedef unsigned long long uintmax_t;
 #endif
 
 #ifndef SIZE_MAX
-#define SIZE_MAX (4294967295UL)
+#define SIZE_MAX (4294967295U)
 #endif
 
 #ifndef WCHAR_MIN

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