Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

# and ## order of expansion

The C standard gives the following example:

#define hash_hash # ## #
#define mkstr(a) # a
#define in_between(a) mkstr(a)
#define join(c, d) in_between(c hash_hash d)
char p[] = join(x, y); // equivalent to char p[] = "x ## y";

But it also says 'The order of evaluation of # and ## operators is unspecified.'

Why is the expansion of hash_hash guaranteed to be interpreted as the ## operator applied to #'s, instead of the # operator applied to ##?

like image 413
rwallace Avatar asked Jan 18 '13 09:01

rwallace


1 Answers

Because '#' only acts as an operator if it appears in a function-like macro and is followed by a parameter name ... but hash_hash isn't a function-like macro and those '#' aren't followed by parameter names.

like image 81
Jim Balter Avatar answered Oct 13 '22 22:10

Jim Balter