Topic: #if USHRT_MAX==4294967295" - wrong?
Author: sabroe@daimi.aau.dk (Morten Sabroe Mortensen)
Date: Fri, 29 Jan 93 20:49:35 GMT Raw View
Until this moment, I've used the following code without any trouble whatsoever:
/*** FILE "fnd.h" *************************************************************/
#ifndef _fnd_h_
#define _fnd_h_
#include <limits.h>
/******************************************************************************/
#if !(defined EXACT_MATCH) && !(defined BEST_MATCH)
#define EXACT_MATCH
#endif
/* The unsigned integer types nX are guarantied to cover 0..2^X-1,
* the signed integer types zX are guarantied to cover -2^X..2^X-1!
*/
#ifdef EXACT_MATCH
...
/* n32: */
#if USHRT_MAX==4294967295 //WARNING!
typedef unsigned short int n32; //0..4294967295
#elif UINT_MAX==4294967295 //WARNING!
typedef unsigned int n32;
#elif ULONG_MAX==4295967295
typedef unsigned long int n32;
#else
#error "fnd.h: Unable to find exact match for integer-type n32!"
#endif
...
/* z32: */
#if SHRT_MIN==-2147483648 && SHRT_MAX==2147483647 //WARNING!
typedef signed short int z32; //-2147483648..2147483647
#elif INT_MIN==-2147483648 && INT_MAX==2147483647 //WARNING!
typedef signed int z32;
#elif LONG_MIN==-2147483648 && LONG_MAX==2147483647
typedef signed long int z32;
#else
#error "fnd.h: Unable to find exact match for integer-type z32!"
#endif
#else
...
/* n32: */
#if USHRT_MAX>=4294967295
typedef unsigned short int n32; //0..4294967295
#elif UINT_MAX>=4294967295
typedef unsigned int n32;
#elif ULONG_MAX>=4295967295
typedef unsigned long int n32;
#else
#error "fnd.h: Unable to match integer-type n32!"
#endif
...
/* z32: */
#if SHRT_MIN<=-2147483648 && SHRT_MAX>=2147483647
typedef signed short int z32; //-2147483648..2147483647
#elif INT_MIN<=-2147483648 && INT_MAX>=2147483647
typedef signed int z32;
#elif LONG_MIN<=-2147483648 && LONG_MAX>=2147483647
typedef signed long int z32;
#else
#error "fnd.h: Unable to match integer-type z32!"
#endif
#endif
...
#endif
/*** "fnd.h" ******************************************************************/
I have tried this with various compilers and have never meet one, that can't
find an exact match!
Now I'm trying gcc 2.3.3 for the first time, and it gives me the following
error (the four lines are marked with "WARNING!" in the above code):
fnd.h:47: warning: integer constant is so large that it is unsigned
fnd.h:49: warning: integer constant is so large that it is unsigned
fnd.h:78: warning: integer constant is so large that it is unsigned
fnd.h:80: warning: integer constant is so large that it is unsigned
Can it really be true, the preprocessor knows about types, f.ex. signed and
unsigned? I don't understand that; why in the world does the preprocessor
not just treat everything as strings - then there would be no problems
comparing numbers of arbitrary size, i guess!?
If I'm testing in a wrong way, how should it then be done?
-- Morten.