Detect integer sizes without running executables
Try to compile test code for sizes 1, 2, 4, 8 that only succeeds if a
type has a certain size. The test code contains an array declaration
of the form:
int a[sizeof(type) == size ? 1 : -1];
The array size is a valid constant expression but produces a
compilation error unless the the size of the type matches. This makes
it possible to determine the size of types without executing any test
programs when cross-compiling.
Inspired by Autoconf's AC_CHECK_SIZEOF.
3 files changed