User`s manual

28 digi.com Language
4.5.2 Nested Macro Definitions
Generally speaking, Dynamic C expands macro calls recursively until they can expand no more. Another
way of stating this is that macro definitions can be nested.
The exceptions to this rule are
1. Arguments to the # and ## operators are not expanded.
2. To prevent infinite recursion, a macro does not expand within its own expansion.
The following complex example illustrates this.
The code
will expand first to
then to
then to
and finally to
#define A B
#define B C
#define uint unsigned int
#define M(x) M ## x
#define MM(x,y,z) x = y ## z
#define string something
#define write( value, fmt )\
printf( #value "=" #fmt "\n", value )
uint z;
M (M) (A,A,B);
write(string, %s);
unsigned int z; // simple expansion
MM (A,A,B); // M(M) doesn’t expand recursively
printf( "string" "=" "%s" "\n", string ); // #value "string" #fmt "%s"
unsigned int z;
A = AB; // from A = A ## B
printf( "string" "=" "%s" "\n", something );
// string something
unsigned int z;
B = AB; // A B
printf( "string=%s\n", something ); // concatenation
unsigned int z;
C = AB; // B C
printf("string = %s\n", something);