I have a question about the macro shown as follows:
What does 0##a mean here?Code:#define _MUXSELf(a) 0##a << 30
Thanks for the help,
aayu
Printable View
I have a question about the macro shown as follows:
What does 0##a mean here?Code:#define _MUXSELf(a) 0##a << 30
Thanks for the help,
aayu
It basically joins the tokens on its right and left, e.g., if a was 123, you would end up with 0123 << 30.
Thanks.
aayu
I try to test the macro by using the following code:
after using:Code:#include <stdlib.h>
#include <stdio.h>
#define ttoken(a) 0##a << 2
int main()
{
int a = 8;
int b;
b = ttoken(a);
printf("b = %d\n", b);
return 0;
}
the following is the compiler error:Code:gcc -std=c99 token1.c
Anything wrong here?Code:token1.c:10:1: error: invalid suffix "a" on integer constant
Thanks again,
aayu
Yes, the fact that you wrote ttoken(a). You should be using octal digits instead, e.g., ttoken(71).
You are correct. But why I have to use octal digits, I tryied to use hex or dec, the compiler complained except using octal digits. I must missed something here.
Thanks,
aayu
In C, a number that starts with a 0 is in octal, just as a number that starts 0x is in hex.
And the "##" preprocessor operators are used for string catenation.
Why not? It exactly what it does...
as I said it replaces char sequence ttoken(a) with char sequence 0a
or char sequence ttoken(71) with char sequence 071
I'm not sure using word strings here is helpful as it conflicts with C-term... there are no C-strings involved here