I have come across this code and I am not sure what #reg
is doing:
#define FPGA_WRITE(reg,val) do { printf("%-20s %08X <<- %08lX\n", #reg, (reg), (unsigned long)(val));} while (0)
int main()
{
FPGA_WRITE(10,15);
return 0;
}
This prints this following:
10 0000000A <<- 0000000F
If I take out the #
, I get a segfault when I execute the code. Strange. What is the usage of #
?
It is Stringizing Operator (#) used inside #define
pre-processor macros,
which turns the argument it precedes into a quoted string
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