Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

values in gcc 1.40 limits.h are of the wrong type

0 views
Skip to first unread message

Paul Eggert

unread,
Jun 7, 1991, 10:12:25 PM6/7/91
to
The following program should compile and run without incident on a
typical 32-bit machine:

#include "limits.h"

__typeof__(LONG_MAX) long1;
__typeof__(LONG_MIN) long2;
__typeof__(ULONG_MAX) ulong;

int p(long *a, long *b, unsigned long *c) { return *a + *b + *c;}

int main()
{
if (UCHAR_MAX < -UCHAR_MAX) printf("UCHAR_MAX is broken\n");
if (USHRT_MAX < -USHRT_MAX) printf("USHRT_MAX is broken\n");
return p(&long1, &long2, &ulong);
}

But with GCC 1.40 (sparc, SunOS 4.1.1), both compilation and execution
generate messages:

211-ata% gcc -I. t.c
t.c: In function main:
t.c:13: warning: argument passing between incompatible pointer types
t.c:13: warning: argument passing between incompatible pointer types
t.c:13: warning: argument passing between incompatible pointer types
212-ata% ./a.out
UCHAR_MAX is broken
USHRT_MAX is broken

The problem is that some of the _MAX values have the wrong type in limits.h.
The ANSI C standard, section 2.2.4.2.1, says that these macros ``shall be
replaced by expressions that have the same type as would an expression that is
an object of the corresponding type converted according to the integral
promotions''. In GCC 1.40, UCHAR_MAX and USHRT_MAX are unsigned, whereas they
should be int. Also, LONG_MIN and LONG_MAX are int, whereas they should be
long; and ULONG_MAX is unsigned, whereas it should be unsigned long.

Here is a patch.

*** limits.h-1.40 Wed Jan 31 23:03:55 1990
--- limits.h Fri Jun 7 18:35:17 1991
***************
*** 10,14 ****

/* Maximum value an `unsigned char' can hold. (Minimum is 0). */
! #define UCHAR_MAX 255U

/* Minimum and maximum values a `char' can hold. */
--- 10,14 ----

/* Maximum value an `unsigned char' can hold. (Minimum is 0). */
! #define UCHAR_MAX 255

/* Minimum and maximum values a `char' can hold. */
***************
*** 15,19 ****
#ifdef __CHAR_UNSIGNED__
#define CHAR_MIN 0
! #define CHAR_MAX 255U
#else
#define CHAR_MIN (-128)
--- 15,19 ----
#ifdef __CHAR_UNSIGNED__
#define CHAR_MIN 0
! #define CHAR_MAX 255
#else
#define CHAR_MIN (-128)
***************
*** 26,30 ****

/* Maximum value an `unsigned short int' can hold. (Minimum is 0). */
! #define USHRT_MAX 65535U

/* Minimum and maximum values a `signed int' can hold. */
--- 26,30 ----

/* Maximum value an `unsigned short int' can hold. (Minimum is 0). */
! #define USHRT_MAX 65535

/* Minimum and maximum values a `signed int' can hold. */
***************
*** 38,43 ****
(Same as `int'). */
#define LONG_MIN (-LONG_MAX-1)
! #define LONG_MAX 2147483647

/* Maximum value an `unsigned long int' can hold. (Minimum is 0). */
! #define ULONG_MAX 4294967295U
--- 38,43 ----
(Same as `int'). */
#define LONG_MIN (-LONG_MAX-1)
! #define LONG_MAX 2147483647L

/* Maximum value an `unsigned long int' can hold. (Minimum is 0). */
! #define ULONG_MAX 4294967295UL

0 new messages