I searched far and wide and information on the net seems to suggest that conditional compilation using the preprocessor works exclusively on environment variables.
Basically, I would like to have an inline function or macro perform different operations based in its input arguments. Example of what I want to achieve:
inline void foo(int x) { #if (x < 32) register0 |= (1 << x); #else register1 |= (1 << (x - 32)); #endif } The main goal here is that the resulting inline code will not contain conditional code for constant inputs.
Basically, I currently program for a microcontroller (lpc213x) and would like to have an inline function or macro to do pin configuration setup. Since pin configurations are split across multiple registers (e.g. 0 and 1 above), I would like to perform some conditional checks to decide which register is supposed to be written to for a given pin constant.
However, the pin configurations are all constant at compile time, so I would like to eliminate the conditional checks from compile code. I know that optimization would likely get rid of unnecessary conditionals anyway, but I'm wondering whether there is a way to achieve this behavior explicitly, because I might need to disable optimization in the future.
Thanks,
FRob
constexprin C++.x < 32, notx <= 32(and the1should probably be1U).