Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #110248 > unrolled thread

Token concatenation

Started byHans-Peter Diettrich <DrDiettrich1@aol.com>
First post2017-05-18 03:25 +0200
Last post2017-05-18 11:17 +0100
Articles 2 — 2 participants

Back to article view | Back to comp.lang.c


Contents

  Token concatenation Hans-Peter Diettrich <DrDiettrich1@aol.com> - 2017-05-18 03:25 +0200
    Re: Token concatenation Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-05-18 11:17 +0100

#110248 — Token concatenation

FromHans-Peter Diettrich <DrDiettrich1@aol.com>
Date2017-05-18 03:25 +0200
SubjectToken concatenation
Message-ID<eo4bg1Flha4U1@mid.individual.net>
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

[toc] | [next] | [standalone]


#110262

FromBen Bacarisse <ben.usenet@bsb.me.uk>
Date2017-05-18 11:17 +0100
Message-ID<87lgpuzcy5.fsf@bsb.me.uk>
In reply to#110248
Hans-Peter Diettrich <DrDiettrich1@aol.com> writes:

> 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.

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.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.c


csiph-web