Discussion:
Token concatenation
(too old to reply)
Hans-Peter Diettrich
2017-05-18 01:25:19 UTC
Permalink
Raw Message
In the Windows headers (driverspecs.h) I found a strange use of the ##
operator, like this pattern:
#define foo(x) bar(##baz(x))

A (baz concatenation is invalid, does not result in a valid preprocessor
token.

Can somebody explain the intended evaluation?

DoDi
Ben Bacarisse
2017-05-18 10:17:22 UTC
Permalink
Raw Message
Post by Hans-Peter Diettrich
#define foo(x) bar(##baz(x))
A (baz concatenation is invalid, does not result in a valid
preprocessor token.
I'm stumped as to the purpose since, as you say, it's undefined. My
only thought is that in an implementation where an invalid pasting
produces some new symbol unlike the old one this code might prevent baz
from being expanded no matter what defines are in place at the time.

If you can find a compiler that does not complain (presumably the one
the header file is intended for) you could try

#define foo(x) bar(##baz(x))
#define baz(x) BAZ[x]
#define s(x) S(x)
#define S(x) #x
s(foo(arg))

so see if that gives you any clues.
--
Ben.
Loading...