I am trying to define a structure in C for a square where each side can either have a given color (labeled by int) or not have any color at all.
I would like my struct to behave like a named tuple, i.e allow for referring to the north color by square.n = 0;
or square.c[NORTH_DIRECTION] = 0;
interchangeably.
Is the following a correct way to do it:
typedef struct {
union {
struct {
int n, e, s, w;
};
int c[4];
};
union {
struct {
bool n_is_null, e_is_null, s_is_null, w_is_null;
};
bool is_null[4];
};
} SquareColors;
Thank you very much!