wut/include/wut_structsize.h

33 lines
1009 B
C
Raw Normal View History

2016-01-07 13:07:13 +01:00
#pragma once
#include <assert.h>
#include <stddef.h>
// Ensure structs are correct size & offsets
#if defined(static_assert)
# define CHECK_SIZE(Type, Size) \
static_assert(sizeof(Type) == Size, \
#Type " must be " #Size " bytes")
2016-01-07 13:07:13 +01:00
# define CHECK_OFFSET(Type, Offset, Field) \
static_assert(offsetof(Type, Field) == Offset, \
#Type "::" #Field " must be at offset " #Offset)
#else
# define CHECK_SIZE(Type, Size)
# define CHECK_OFFSET(Type, Offset, Field)
#endif
2016-01-07 13:07:13 +01:00
// Workaround weird macro concat ## behaviour
#define PP_CAT(a, b) PP_CAT_I(a, b)
#define PP_CAT_I(a, b) PP_CAT_II(~, a ## b)
#define PP_CAT_II(p, res) res
// Allow us to easily add UNKNOWN / PADDING bytes into our structs,
// generates unique variable names using __COUNTER__
#define UNKNOWN(Size) char PP_CAT(__unk, __COUNTER__) [Size]
#define PADDING(Size) UNKNOWN(Size)
// Just some placeholder defines
#define UNKNOWN_ARG uint32_t
#define UNKNOWN_ARGS void
#define UNKNOWN_SIZE(x)