Hi,
I would like to do some simple math with the proprocessor, but it seems not to be possible.
#define SOMECOUNTER 0 /*Step 1: */ #ifdef Condition_1 # ifdef SOMECOUNTER # define TEMPCOUNTER SOMECOUNTER + 1 # undef SOMECOUNTER # define SOMECOUNTER TEMPCOUNTER # undef TEMPCOUNTER # endif #endif /*Step 2: */ #ifdef Condition_2 # ifdef SOMECOUNTER # define TEMPCOUNTER SOMECOUNTER + 1 # undef SOMECOUNTER # define SOMECOUNTER TEMPCOUNTER # undef TEMPCOUNTER # endif #endif /*Step 3: */ #ifdef Condition_3 # ifdef SOMECOUNTER # define TEMPCOUNTER SOMECOUNTER + 1 # undef SOMECOUNTER # define SOMECOUNTER TEMPCOUNTER # undef TEMPCOUNTER # endif #endif
I would like it to end up with a line in this vein:0 + 1 + 1 +....+1
as a value for the number of elements of an array. However, the compiler keeps telling me that "TEMPCOUNTER" is not defined, right after I defined it.
Can someone shed a bit of light on my dim wits?
OldFart
Looks rather complicated to me.
Why not like this:
In the best case you could even use condition_x as a 0/1 value and do