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
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.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
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).
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
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.
All problems in computer science can be solved by another level of indirection,
except for the problem of too many layers of indirection.
– David J. Wheeler