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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T15:20:12+00:00 2026-05-14T15:20:12+00:00

At least some C preprocessors let you stringize the value of a macro, rather

  • 0

At least some C preprocessors let you stringize the value of a macro, rather than its name, by passing it through one function-like macro to another that stringizes it:

#define STR1(x) #x
#define STR2(x) STR1(x)
#define THE_ANSWER 42
#define THE_ANSWER_STR STR2(THE_ANSWER) /* "42" */

Example use cases here.

This does work, at least in GCC and Clang (both with -std=c99), but I’m not sure how it works in C-standard terms.

Is this behavior guaranteed by C99?
If so, how does C99 guarantee it?
If not, at what point does the behavior go from C-defined to GCC-defined?

  • 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-14T15:20:13+00:00Added an answer on May 14, 2026 at 3:20 pm

    Yes, it’s guaranteed.

    It works because arguments to macros are themselves macro-expanded, except where the macro argument name appears in the macro body with the stringifier # or the token-paster ##.

    6.10.3.1/1:

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

    So, if you do STR1(THE_ANSWER) then you get “THE_ANSWER”, because the argument of STR1 is not macro-expanded. However, the argument of STR2 is macro-expanded when it’s substituted into the definition of STR2, which therefore gives STR1 an argument of 42, with the result of “42”.

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

Sidebar

Related Questions

Every PHP programmer likely uses at least some form of a template engine and
Some background: In Germany (at least) invoice numbers have to follow certain rules: The
I am working with some CSS that is poorly written to say the least.
I was doing some testing and straight LINQ-to-SQL queries run at least 80% faster
I've created some fairly simple XAML, and it works perfectly (at least in KAXML).
Is there some way to get a value from the last inserted row? I
In at least some of the PowerShell v2 CTPs, there was a cmdlet known
I was writing some Unit tests last week for a piece of code that
Last time I asked about the reverse process , and got some very efficient
Can someone give some hints of how to delete the last n lines from

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.