Fix wut_structsize.h for compilers which do not have static_assert (pre C11)

This commit is contained in:
James Benton 2017-02-21 20:06:18 +00:00
parent 1a1a87a948
commit bb7d180e40

View File

@ -3,6 +3,7 @@
#include <stddef.h> #include <stddef.h>
// Ensure structs are correct size & offsets // Ensure structs are correct size & offsets
#if defined(static_assert)
# define CHECK_SIZE(Type, Size) \ # define CHECK_SIZE(Type, Size) \
static_assert(sizeof(Type) == Size, \ static_assert(sizeof(Type) == Size, \
#Type " must be " #Size " bytes") #Type " must be " #Size " bytes")
@ -10,6 +11,10 @@
# define CHECK_OFFSET(Type, Offset, Field) \ # define CHECK_OFFSET(Type, Offset, Field) \
static_assert(offsetof(Type, Field) == Offset, \ static_assert(offsetof(Type, Field) == Offset, \
#Type "::" #Field " must be at offset " #Offset) #Type "::" #Field " must be at offset " #Offset)
#else
# define CHECK_SIZE(Type, Size)
# define CHECK_OFFSET(Type, Offset, Field)
#endif
// Workaround weird macro concat ## behaviour // Workaround weird macro concat ## behaviour
#define PP_CAT(a, b) PP_CAT_I(a, b) #define PP_CAT(a, b) PP_CAT_I(a, b)