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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:28:46+00:00 2026-05-24T05:28:46+00:00

GNU’s cpp allows you to turn macro parameters into strings like so #define STR(x)

  • 0

GNU’s cpp allows you to turn macro parameters into strings like so

#define STR(x) #x

Then, STR(hi) is substituted with "hi"

But how do you turn a macro (not a macro parameter) into a string?

Say I have a macro CONSTANT with some value e.g.

#define CONSTANT 42

This doesn’t work: STR(CONSTANT). This yields "CONSTANT" which is not what we want.

  • 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-24T05:28:46+00:00Added an answer on May 24, 2026 at 5:28 am

    The trick is to define a new macro which calls STR.

    #define STR(str) #str
    #define STRING(str) STR(str)
    

    Then STRING(CONSTANT) yields "42" as desired.

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

Sidebar

Related Questions

I use CMake with GNU Make and would like to see all commands exactly
Is GNU gettext built in into Wordpress or do I have to download it
Using GNU's make, I'd like to extract the first character of a variable. Currently
Using GNU bash (version 4.0.35(1)-release (x86_64-suse-linux-gnu), I would like to negate a test with
http://gcc.gnu.org/onlinedocs/gcc-2.95.3/objc-features_1.html#SEC2 The GNU Objective-C runtime provides a way that allows you to execute code
Because GNU make allows variables to be as large as memory allows, it has
I compiled GNU Emacs 23.2.1 on remote host but really want to use command
Using GNU sed , I need to remove parenthetical phrases like (click here ....)
The Gnu C++ compiler seems to define __cplusplus to be 1 #include <iostream> int
In Matlab or GNU Octave I'd like to do something like this: x=struct('a',1,'b',2,'c',[1 2;3

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.