P99

◆ P99_DEFINE_UNION

#define P99_DEFINE_UNION (   NAME,
  ... 
)
Value:
\
union NAME { \
uint8_t p00_allbytes[sizeof(union { __VA_ARGS__ })]; \
__VA_ARGS__ \
}

definition of a union NAME

The member declaration(s) should be given as the variable argument list.

The difference between this and a straightforward union declaration is that here we introduce a hidden first member that consists of a byte array with just the appropriate length to cover the whole union. The only purpose of this hidden member is to ensure that the default initializer { 0 } initializes the whole union.

Otherwise in C99 padding bytes could be omitted from such an initialization, which can lead to surprising results. C1x explicitly states that padding bytes must be initialized to 0. So from then on we can use a straight union definition.

Warning
Don't assume anything about the ordering of the members of this union. Use designated initializers such as { .toto = { .a = 1, }, }, instead.
Remarks
argument 0 must be an identifier

Definition at line 106 of file p99_type.h.