incorrect enum warning?

Stefan Farfeleder stefan at fafoe.dyndns.org
Thu May 1 08:20:28 PDT 2003


On Thu, May 01, 2003 at 10:07:13AM -0500, Jacques A. Vidrine wrote:
> On Thu, May 01, 2003 at 04:51:40PM +0200, Dag-Erling Smorgrav wrote:
> > Why does the following code in OpenPAM headers:
> > 
> > enum {
> >         PAM_SILENT                      = 0x80000000,

<...>

> > };
> > 
> > cause the following warning when compiled with CSTD=c99:
> > 
> > /usr/src/contrib/openpam/include/security/pam_constants.h:100: warning: ISO C restricts enumerator values to range of `int'
> > 
> > when 0x80000000 is clearly within the range of 'int' on all platforms
> > we support?
> 
> Guessing:
> C does not specify one's complement or two's complement representation
> of integers.  On a one's complement 32-bit platform, 0x80000000 is -0
> (negative zero), which cannot be an `int'.

6.4.4.1 Integer constants

<...>

The type of an integer constant is the first of the corresponding list
in which its value can be represented.

int
unsigned int
long int
unsigned long int
long long int
unsigned long long int

[This is for hexadecimal constants without suffix.]

Because 0x80000000 > INT_MAX on 32-Bit architectures, 0x80000000 has
type unsigned.  But enumeration constants always have type int, that's
why you're getting this warning.

Regards,
Stefan Farfeleder


More information about the freebsd-hackers mailing list