#define LED1_ON() { /* twiddle port bit */ }
#define LED2_ON() { /* twiddle port bit */ }
// ...
#define LED9_ON() { /* twiddle port bit */ }
#define LED_ON(x) LED##x_ON()
I would like to use the above code (or something similar) to have (for example) LED_ON(1) call macro LED1_ON(), or LED_ON(2) call macro LED2_ON().
I believe it is possible to make cpp do this, but clearly I don't have the syntax correct. Does anyone know the syntax to make this possible?
On the line where I call the LED_ON(2), gcc gives the error message:
undefined reference to `LEDx_ON'
LED_ON(3)rather thanLED3_ON(); nothing other than a literal3would work. On the other hand, an inline function (or even a non-inline function) could easily use aswitchstatement that invokes the proper lower-level macro. - Keith ThompsonLED_ON(n)and redefine#define LED1_ON() LED_ON(1), etc. - Jonathan Leffler