Is there a way to design a macro that could ensure an element is at the start of a struct during it's definition? For example:
typedef struct {
START(int a);
} b;
// Becomes
typedef struct {
int a;
} b;
But generate a compiletime error when it isn't the first element?
typedef struct {
int c;
START(int a);
} b;
// Generate an error
I was thinking you could use a combo of the OFFSETOF
and BUILD_BUG_ON_ZERO
macros but this would require knowing the struct layout while initializing it, and produces an error because the variable is undeclared.
Is this possible in C?