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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T09:37:08+00:00 2026-06-16T09:37:08+00:00

Consider this: #define STRINGIFY(A) #A If I then later write: STRINGIFY(hello) Is the compiler

  • 0

Consider this:

  #define STRINGIFY(A) #A

If I then later write:

 STRINGIFY(hello)

Is the compiler actually seeing this:

 #hello

I think it is that additional hash in front of #A that is confusing me.

  • 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-06-16T09:37:10+00:00Added an answer on June 16, 2026 at 9:37 am

    No, the compiler will put the argument between quotes, resulting in this:

    "hello"
    

    However, beware that macro substitution doesn’t take place near # and ##, so if you really need to stringify the argument (even if it’s another macro) it’s better to write two macros, the first one to expand the argument and the other one to add quotes:

    #define STRINGIFY(x) STRINGIFY_AUX(x)
    #define STRINGIFY_AUX(x) #x
    

    Or more generally, if you’re compiler supports variadic macros (introduced in C99):

    #define STRINGIFY(...) STRINGIFY_AUX(__VA_ARGS__)
    #define STRINGIFY_AUX(...) #__VA_ARGS__
    

    If you really need a function-like macro that paste a # at the beginning of the argument, I think you need it to generate a string (otherwise you’d make an invalid token for the compiler), so you could simple generate two string literals that the compiler will “paste”:

    #include <stdio.h>
    
    #define STRINGIFY(...) STRINGIFY_AUX(__VA_ARGS__)
    #define STRINGIFY_AUX(...) #__VA_ARGS__
    
    int main(void)
    {
      puts(STRINGIFY(#) STRINGIFY(hello));
    }
    

    The main body will look like this in the preprocessor output:

    puts("#" "hello");
    

    I hope this is not an obscure corner of the preprocessor that results in undefined behavior, but it shouldn’t be a problem since we’re not generating another preprocessor instruction.

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

Sidebar

Related Questions

Consider this code; #define A 5 #define B 3 int difference = A -
Consider this #define : #define msd_buffer ((volatile char *) MSD_BUFFER_ADDRESS) and this variable definition:
Consider this code: #define N_ 0 #define N_X 1 #define M(a) N_ M(arg)X; //
Consider this: #ifndef GUARD_H #define GUARD_H ... #endif GUARD_H rather than: #ifndef GUARD_H #define
Consider this code: #include <stdio.h> #define N 5 void printMatrix(int (*matrix)[N],int n) { int
Consider this (horrible, terrible, no good, very bad) code structure: #define foo(x) // commented
Consider this macro: #define MAKE_TEMPLATE(...) template <typename T, __VA_ARGS__ > When used with zero
Consider this unhygienic Scheme macro: (define-macro for (lambda (i i1 i2 . body) (let
Consider this program: #include <map> #include <string> #define log magic_log_function // Please don't mind
To demonstrate my problem, consider this simple program that does not compile: #include <boost/noncopyable.hpp>

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.