Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why to write three define here? #801

Closed
shuaitq opened this issue Nov 28, 2016 · 1 comment
Closed

Why to write three define here? #801

shuaitq opened this issue Nov 28, 2016 · 1 comment

Comments

@shuaitq
Copy link

shuaitq commented Nov 28, 2016

Hello!
I see your code. And I'm very confused why you should write like following.

rapidjson.h
#define RAPIDJSON_JOIN(X, Y) RAPIDJSON_DO_JOIN(X, Y)
#define RAPIDJSON_DO_JOIN(X, Y) RAPIDJSON_DO_JOIN2(X, Y)
#define RAPIDJSON_DO_JOIN2(X, Y) X##Y

Could you tell me why?
Thanks!

@pah
Copy link
Contributor

pah commented Jul 12, 2017

The first indirection is needed in order to expand eventual macros in X or Y:

#define FOO foo
#define BAR bar
// without indirection - concatenates unexpanded arguments
RAPIDJSON_DO_JOIN2(FOO, BAR) // --> FOOBAR
// with indirection    - concatenates expanded arguments
RAPIDJSON_JOIN(FOO,BAR)      // --> foobar

The second indirection is probably no longer needed on today's preprocessors.

@esrrhs esrrhs closed this as completed Nov 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants