J
JesusWaffle
I'm trying to portably define a type which is wide enough to hold an
int, a wchar_t, or a void *. Here's what I've got:
#include <stdint.h>
#include <wchar.h>
#include <limits.h>
#if INT_MAX > INT32_MAX || WCHAR_MAX > INT32_MAX || \
INTPTR_MAX > INT32_MAX
typedef int64_t funky_type;
#elif INT_MAX > INT16_MAX || WCHAR_MAX > INT16_MAX || \
INTPTR_MAX > INT16_MAX
typedef int32_t funky_type;
#else
typedef int16_t funky_type;
#endif
There seem to be a lot of language lawyers here, so: are there any
corner cases that my definition misses? Will it be wide enough in all
cases? Are there any simplifications I could make?
int, a wchar_t, or a void *. Here's what I've got:
#include <stdint.h>
#include <wchar.h>
#include <limits.h>
#if INT_MAX > INT32_MAX || WCHAR_MAX > INT32_MAX || \
INTPTR_MAX > INT32_MAX
typedef int64_t funky_type;
#elif INT_MAX > INT16_MAX || WCHAR_MAX > INT16_MAX || \
INTPTR_MAX > INT16_MAX
typedef int32_t funky_type;
#else
typedef int16_t funky_type;
#endif
There seem to be a lot of language lawyers here, so: are there any
corner cases that my definition misses? Will it be wide enough in all
cases? Are there any simplifications I could make?