#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'
You need to define LED_ON
as
#define LED_ON(x) LED##x##_ON()
you want to take the argument x
and paste on an LED
prefix and a _ON
suffix.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With