I have built a working C library, that uses constants, in header files defined as
typedef struct Y {
union {
struct bit_field bits;
uint8_t raw[4];
} X;
} CardInfo;
static const CardInfo Y_CONSTANT = { .raw = {0, 0, 0, 0 } };
I know that the .raw
initializer is C only syntax.
How do I define constants with unions in them in a way such that I can use them in C and C++.
union
s by the first element? I.e.static const Y_CONSTANT = {{0,0,0,0}};
– Trenttrentobit_field
would have a constructor to initialize its members, and you would hardly need the union. When you go for the least common denominator, you are limiting yourself. – Schizophrenia