At compilation time it's IMPOSSIBLE to know the values of the variables, because they change at runtime, that's why everything I suggest was at runtime.
Once I define a MACRO for every bitposition and then test it at compilation time, maybe it helps. I'll explain what I did:
Lets assume you have and 8bit register where every bitposition is a flag. It could be described as:
msb lsb
| F7 | F6 | F5 | F4 | F3 | F2 | F1 | F0 |
Then you have a variable wich uses this structure (in your case it will be var1) , then when initializing var1 you do something like this:
var1.F7 = 1;var1.F4 = 1;var1.F3 = 1;
Now, what you can do is add some macro definitions, for every falg initialization, where the value of the macro is the mask for the corresponding flag:
// Every bit-mask definition for var1#define MACRO_var1_F7 0x80#define MACRO_var1_F6 0x40#define MACRO_var1_F5 0x20#define MACRO_var1_F4 0x10#define MACRO_var1_F3 0x08#define MACRO_var1_F2 0x04#define MACRO_var1_F1 0x02#define MACRO_var1_F0 0x01// Value of macro corresponding with initialization values#define MACRO_var1 (MACRO_var1_F7 + MACRO_var1_F4 + MACRO_var1_F3) // Wrong initilization#define MACRO_var1_WRONG (MACRO_var1_F7 + MACRO_var1_F4 + MACRO_var1_F3 + MACRO_var1_F0) var1 = MACRO_var1; // Replace everybit initialization with macro value#if (MACRO_var1 == MACRO_var1_WRONG) #error "Wrong var1 initialization"#endif
I don't know if I made myself clear, but that's the closer you can get if you want to detect and init error at compilation time
Hope it helps!