Hello,
Is there a rule to the effect that preprocessor macros involving the # and ## operators are executed before other macros? For example, the following program
Code:
#include <stdio.h>
#include <stdlib.h>
#define X 1
#define Y 3
#define Z surprise
#define r(a, b) a##b
#define s(c) #c
int main()
{
printf("%d\n", r(X, Y));
printf("%s\n", s(Z));
return 0;
}
yields a compilation error message "error: 'XY' undeclared". I take it that this means the fourth macro concatinated the X and Y before the first two macros had a chance to substitute for them.
If the first printf() is commented out and the program is compiled and run, the output is "Z". That suggests that fifth macro has stringised the Z before the third macro substituted for it.
This sort of suprises me, as I had assumed the macros would be executed in the order in which they appeared in the code.
Can anyone shed any light on what is going on here?