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 6843301
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:13:43+00:00 2026-05-27T00:13:43+00:00

At: C++ FAQ – Miscellaneous technical issues – [39.6] What should be done with

  • 0

At: C++ FAQ – Miscellaneous technical issues – [39.6] What should be done with macros that need to paste two tokens together?

Could someone explain to me why? All I read is trust me, but I simply can’t just trust on something because someone said so.

I tried the approach and I can’t find any bugs appearing:

#define mymacro(a) int a ## __LINE__
mymacro(prefix) = 5;
mymacro(__LINE__) = 5;
int test = prefix__LINE__*__LINE____LINE__; // fine

So why do I need to do it like this instead (quote from the webpage):

However you need a double layer of indirection when you use ##.
Basically you need to create a special macro for “token pasting” such
as:

 #define NAME2(a,b)         NAME2_HIDDEN(a,b)
 #define NAME2_HIDDEN(a,b)  a ## b 

Trust me on this — you really need to do
this! (And please nobody write me saying it sometimes works without
the second layer of indirection. Try concatenating a symbol with
__ LINE__ and see what happens then.)

Edit: Could someone also explain why he uses NAME2_HIDDEN before it’s declared below? It seems more logical to define NAME2_HIDDEN macro before I use it. Is it some sort of trick here?

  • 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-27T00:13:43+00:00Added an answer on May 27, 2026 at 12:13 am

    The relevant part of the C spec:

    6.10.3.1 Argument substitution

    After the arguments for the invocation of a function-like macro have been identified,
    argument substitution takes place. A parameter in the replacement list, unless preceded
    by a # or ## preprocessing token or followed by a ## preprocessing token (see below), is
    replaced by the corresponding argument after all macros contained therein have been
    expanded. Before being substituted, each argument’s preprocessing tokens are
    completely macro replaced as if they formed the rest of the preprocessing file; no other
    preprocessing tokens are available.

    The key part that determines whether you want the double indirection or not is the second sentence and the exception in it — if the parameter is involved in a # or ## operation (such as the params in mymacro and NAME2_HIDDEN), then any other macros in the argument are NOT expanded prior to doing the # or ##. If, on the other hand, there’s no # or ## IMMEDIATELY in the macro body (as with NAME2), then other macros in the parameters ARE expanded.

    So it comes down to what you want — sometimes you want all macros expanded FIRST, and then do the # or ## (in which case you want the double layer indirection) and sometime you DO NOT want the macros expanded first (in which case you CAN’T HAVE double layer macros, you need to do it directly.)

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

Sidebar

Related Questions

// http://www.parashift.com/c++-faq-lite/misc-technical-issues.html class BadConversion : public std::runtime_error { public: BadConversion(std::string const& s) : std::runtime_error(s)
Maybe a FAQ at this website. I have a TableViewController that holds a form.
Language FAQ says import scala.collection.mutable.{_, Map => _, Set => _} should import all
From c++ FAQ: http://www.parashift.com/c++-faq-lite/dtors.html#faq-11.9 Remember: delete p does two things: it calls the destructor
I have a FAQ area on my page that has all of the questions
In JUnit FAQ you can read that you shouldn't test methods that are too
I am working on a simple FAQ page that will show/hide answers on clicked
I'm creating a self-help FAQ type application and one of the requirements is that
I found (in http://c-faq.com/ansi/avail.html ) that An electronic (PDF) copy is available on-line, for
This FAQ says that The seq operator is seq :: a -> b ->

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.