F
Francois Grieu
I have code on the tune of
#include <limits.h>
#if 0xFFFFFFFF>=UINT_MAX
typedef unsigned int tu32; /* unsigned at-least-32-bit type */
#define P_TU32 "" /* printf prefix for tu32 (none) */
#else
typedef unsigned long tu32; /* unsigned at-least-32-bit type */
#define P_TU32 "l" /* printf prefix for tu32 */
#endif
It works on all current versions of compilers I use (one of which is 8
years old, and many claim only C89 compatibility, plus a few extensions
like // comments).
However, I am concerned that when UINT_MAX is 0xFFFF, some old preprocessors
might evaluate 0xFFFFFFFF>=0xFFFF as if it was -1>=0xFFFF, and thus take the
wrong branch. From memory, this has hit me once, though I can't pinpoint a
culprit.
Does one know a compiler/preprocessor where #if 0xFFFFFFFF>=UINT_MAX would
not work correctly?
What would be the safest way? What about #if UINT_MAX>>30 >= 3 ?
TIA,
Francois Grieu
#include <limits.h>
#if 0xFFFFFFFF>=UINT_MAX
typedef unsigned int tu32; /* unsigned at-least-32-bit type */
#define P_TU32 "" /* printf prefix for tu32 (none) */
#else
typedef unsigned long tu32; /* unsigned at-least-32-bit type */
#define P_TU32 "l" /* printf prefix for tu32 */
#endif
It works on all current versions of compilers I use (one of which is 8
years old, and many claim only C89 compatibility, plus a few extensions
like // comments).
However, I am concerned that when UINT_MAX is 0xFFFF, some old preprocessors
might evaluate 0xFFFFFFFF>=0xFFFF as if it was -1>=0xFFFF, and thus take the
wrong branch. From memory, this has hit me once, though I can't pinpoint a
culprit.
Does one know a compiler/preprocessor where #if 0xFFFFFFFF>=UINT_MAX would
not work correctly?
What would be the safest way? What about #if UINT_MAX>>30 >= 3 ?
TIA,
Francois Grieu