So what would be a good way to define a preprocessor value which will expand to the correct size of size_t in each platform?
According to the Glibc manual | Width of an Integer Type:
TS 18661-1:2014 defines macros for the width of integer types (the
number of value and sign bits). One benefit of these macros is they
can be used in #if preprocessor directives, whereas sizeof cannot. The
following macros are defined in limits.h.
CHAR_WIDTH
SCHAR_WIDTH
UCHAR_WIDTH
SHRT_WIDTH
USHRT_WIDTH
INT_WIDTH
UINT_WIDTH
LONG_WIDTH
ULONG_WIDTH
LLONG_WIDTH
ULLONG_WIDTH
These are the widths of the types char, signed char, unsigned char,
short int, unsigned short int, int, unsigned int, long int, unsigned
long int, long long int and unsigned long long int, respectively.
Further such macros are defined in stdint.h. Apart from those for
types specified by width (see Integers), the following are defined:
INTPTR_WIDTH
UINTPTR_WIDTH
PTRDIFF_WIDTH
SIG_ATOMIC_WIDTH
SIZE_WIDTH
WCHAR_WIDTH
WINT_WIDTH
These are the widths of the types intptr_t, uintptr_t, ptrdiff_t,
sig_atomic_t, size_t, wchar_t and wint_t, respectively.
According to the manual SIZE_WIDTH
is what you are looking for.
I'm not sure of the availability with compilers like MSVC, XLC and SunCC; or platforms like AIX, OX X, Solaris or Windows.