On Fri, 5 Sep 2014 07:00:24 -0700, Charles Mills wrote:

>Not sure if your question is intended to be serious but on an ANSI C
>compiler there is no way to do substitution inside a literal string.
>However, what could have been accomplished with this:
>
>#define debug(a) printf("the value of a is %d\n", a)
>
>that is, a macro that would print "the value of foo is 27"
>
>can be accomplished with ANSI "stringification":
>
>#define debug(a) printf("the value of %s is %d\n", #a, a)
>
>The preprocessor turns #a into "foo" (including the quotes)
> 
Or, even:

    #define debug(a) printf("the value of " #a " is %d\n", a)

(I believe.)  At times I've needed to do such as:

#define STRINGIFY(x) #x
#define TOSTRING(x) STRINGIFY(x)

#define WHEREAMI (  __FILE__":"TOSTRING(__LINE__) )

... to accomplish a double substitution.  I only understand it
while I'm staring at a web page.  GIYF.

-- gil

----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to [email protected] with the message: INFO IBM-MAIN

Reply via email to