J
James
[...]
Well, this crap actually compiles on Comeau:
#if ! defined (SIZE_MAX)
# define SIZE_MAX ((size_t)-1)
#endif
#if ! defined (PTRDIFF_MAX)
# if (SIZE_MAX == ULONG_MAX)
# define PTRDIFF_MAX LONG_MAX
# define PTRDIFF_MIN LONG_MIN
# elif (SIZE_MAX == UINT_MAX)
# define PTRDIFF_MAX INT_MAX
# define PTRDIFF_MIN INT_MIN
# elif (SIZE_MAX == USHRT_MAX)
# define PTRDIFF_MAX SHRT_MAX
# define PTRDIFF_MIN SHRT_MIN
# elif (SIZE_MAX == UCHAR_MAX)
# define PTRDIFF_MAX SCHAR_MAX
# define PTRDIFF_MIN SCHAR_MIN
# else
# error PTRDIFF_MAX cannot be defined!
# endif
#endif
It also compiles on VS 2010 express and EDG C99...
lol.
However, on my Interix test platform, PTRDIFF_MAX is not defined, and
ptrdiff_t is signed. It's my understanding I can't use the same cast
trick with a signed type.
So what are my options for determining the maximum value representable
in a signed ptrdiff_t variable, when PTRDIFF_MAX is not defined?
Well, this crap actually compiles on Comeau:
#if ! defined (SIZE_MAX)
# define SIZE_MAX ((size_t)-1)
#endif
#if ! defined (PTRDIFF_MAX)
# if (SIZE_MAX == ULONG_MAX)
# define PTRDIFF_MAX LONG_MAX
# define PTRDIFF_MIN LONG_MIN
# elif (SIZE_MAX == UINT_MAX)
# define PTRDIFF_MAX INT_MAX
# define PTRDIFF_MIN INT_MIN
# elif (SIZE_MAX == USHRT_MAX)
# define PTRDIFF_MAX SHRT_MAX
# define PTRDIFF_MIN SHRT_MIN
# elif (SIZE_MAX == UCHAR_MAX)
# define PTRDIFF_MAX SCHAR_MAX
# define PTRDIFF_MIN SCHAR_MIN
# else
# error PTRDIFF_MAX cannot be defined!
# endif
#endif
It also compiles on VS 2010 express and EDG C99...
lol.