I want to define some constants in my C file.
Its assembly code like this:
Const1 = 0
Const2 = 0
IF Condition1_SUPPORT
Const1 = Const1 or (1 shl 6)
Const2 = Const2 or (1 shl 3)
ENDIF
IF Condition2_SUPPORT
Const1 = Const1 or (1 shl 5)
Const2 = Const2 or (1 shl 2)
ENDIF
Could you tell me the simplest way to implement this?
And it should be flexible enough because the number of both my constants and conditions is over 10.
After seeing the first three answers, I guess I need to explain more;
What I want to know is how to redefine my constant based on its previous value.
You can’t redefine the value of a constant once you assign it — if you could, it wouldn’t be a constant, would it? Since it looks like you’re trying to set various bits in a constant based on preprocessor flags, you could
#defineseparate constants for each condition’s contribution, then build the final value at the end:You can then
#undefall the intermediate constants, if namespace pollution is a concern.