I was learning the use of token parsing operator. When I did as follows,
#include <stdio.h>
#define concat(a, b) a##b
int main(int argc, char** argv)
{
printf("%d\n", concat(1, 2));
system("pause");
return 0;
}
Output : 12
But when I tried to pass arguments as variable name,
#include <stdio.h>
#define concat(a, b) a##b
int main(int argc, char** argv)
{
int x = 2;
int y = 3;
printf("%d\n", concat(x, y));
system("pause");
return 0;
}
Got error
'system' undefined; assuming extern returning int
'xy': undeclared identifier
identifier "xy" is undefined
I read in Stackoverflow as "C macros are really preprocessor macros that are expanded before compilation. The variable 'port', doesn't get set until runtime."
Okay, That's not possible. But when I tried this
#include <stdio.h>
#define mult(a, b) a*b
int main(int argc, char** argv)
{
int x = 2;
int y = 3;
printf("%d\n", mult(x, y));
system("pause");
return 0;
}
OUTPUT : 6
Why this has no error, but with ## there's error