Skip to content

Defs: types

Giving a type to padding bytes is misguiding, let’s hide it in a macro

#define pad_nam2 ((c)) _ ## c

byte_union() - union between an uint8_t ‘byte’ element and a bit field

#define byte_union ((name, fields)) \
union { \
uint8_t byte; \
struct { fields } GPACKED(1); \
} GPACKED(1) name

word_union() - union between an uint16_t ‘word’ element and a bit field

#define word_union ((name, fields)) \
union { \
uint16_t word; \
struct { fields } GPACKED(2); \
} GPACKED(2) name

lword_union() - union between an uint32_t ‘lword’ element and a bit field

#define lword_union ((name, fields)) \
union { \
uint32_t lword; \
struct { fields } GPACKED(4); \
} GPACKED(4) name
#define pad_name ((c)) pad_nam2(c)
#define pad ((bytes)) uint8_t pad_name(__COUNTER__)[bytes]

Fixed-width types for bit fields are quite meaningless

typedef unsigned int uint
typedef unsigned int uint
typedef uint8_t u8
typedef uint16_t u16
typedef uint32_t u32
typedef uint64_t u64
typedef int8_t i8
typedef int16_t i16
typedef int32_t i32
typedef int64_t i64