Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3450674
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T09:04:26+00:00 2026-05-18T09:04:26+00:00

My mental model of how the preprocessor works is apparently incomplete, and this is

  • 0

My mental model of how the preprocessor works is apparently incomplete, and this is driving me crazy.

I want to concatenate two tokens, but the second token should be expanded first.

#define ANSWER 42

#define FOO foo_ ## ANSWER

Here, FOO expands to foo_ANSWER, but I want it to be foo_42. So I define a MERGE macro in the hopes that this would somehow expand the arguments before concatenation:

#define MERGE(x, y) x ## y

#define BAR MERGE(bar_, ANSWER)

But BAR still expands to bar_ANSWER instead of bar_42. So I define another macro HELPER:

#define HELPER(x, y) MERGE(x, y)

#define BAZ HELPER(baz_, ANSWER)

And now BAZ is successfully expanded to baz_42. At the moment, this seems like magic to me.

Can anyone explain this behavior to me? How do the expansion rules work exactly?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T09:04:26+00:00Added an answer on May 18, 2026 at 9:04 am

    Read the answer to your question here:

    The problem is that when you have a
    macro replacement, the preprocessor
    will only expand the macros
    recursively if neither the stringizing
    operator # nor the token-pasting
    operator ## are applied to it. So, you
    have to use some extra layers of
    indirection, you can use the
    token-pasting operator with a
    recursively expanded argument

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

All, have I gone mental (this is not the question). I want to convert
From reading this documentation , I've built a mental model of what the command
I'd like to understand this a bit better. The mental model I'm operating with
In my mental model of authentication, a user should be distinct from the way
I think there's a gap in my mental model of WCF authentication, hoping someone
This is a mental excercise that has been bothering me for a while. What
I'm writing this query and I'm running into a mental road block. I keep
I'm sure this is fairly simple, however I have a major mental block on
I'm probably totally betraying my ignorance at this point, but I have pretty much
Having a mental block with going around this query. I have the following tables:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.