pls explain this macro | | |
#define JOIN(s1,s2) printf("%s = %s %s = %s",#s1,s1,#s2,s2) | | | | re: pls explain this macro
Ravi wrote: Quote:
#define JOIN(s1,s2) printf("%s = %s %s = %s",#s1,s1,#s2,s2)
>
What's "pls"? Please put your question in your message body.
Have you tried the macro? Your C book should explain the operation of #
on a macro argument.
--
Ian Collins. | | | | re: pls explain this macro
On Wednesday 18 Jul 2007 1:53 pm, in comp.lang.c, Ravi
<ra.ravi.rav@gmail.comwrote:
Message ID: <1184747027.585196.289450@j4g2000prf.googlegroups. com> Quote:
#define JOIN(s1,s2) printf("%s = %s %s = %s",#s1,s1,#s2,s2)
The name JOIN is rather misleading. The # preprocessor operator
causes it's accompanying argument to be "stringised", i.e., for it
to enclosed within double quotes before further processing.
So in your case, if you write:
JOIN(str1, str2)
the replacement token would be:
printf("%s = %s %s = %s", "str1", str1, "str2", str2); | | | | re: pls explain this macro
santosh said: Quote:
On Wednesday 18 Jul 2007 1:53 pm, in comp.lang.c, Ravi
<ra.ravi.rav@gmail.comwrote:
Message ID: <1184747027.585196.289450@j4g2000prf.googlegroups. com>
> Quote:
>#define JOIN(s1,s2) printf("%s = %s %s = %s",#s1,s1,#s2,s2)
>
The name JOIN is rather misleading. The # preprocessor operator
causes it's accompanying argument to be "stringised", i.e., for it
to enclosed within double quotes before further processing.
>
So in your case, if you write:
>
JOIN(str1, str2)
>
the replacement token would be:
>
printf("%s = %s %s = %s", "str1", str1, "str2", str2);
Not quite. It would be:
printf("%s = %s %s = %s","str1",str1,"str2",str2)
The most important difference is, of course, that your semicolon is
spurious.
--
Richard Heathfield <http://www.cpax.org.uk>
Email: -www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999 | | | | re: pls explain this macro
On Wednesday 18 Jul 2007 3:12 pm, in comp.lang.c, Richard Heathfield
<rjh@see.sig.invalidwrote:
Message ID: <6fWdnewKTZl2QgDbRVnygwA@bt.com> Quote:
santosh said:
> Quote:
>On Wednesday 18 Jul 2007 1:53 pm, in comp.lang.c, Ravi
><ra.ravi.rav@gmail.comwrote:
>Message ID: <1184747027.585196.289450@j4g2000prf.googlegroups. com>
>> Quote:
>>#define JOIN(s1,s2) printf("%s = %s %s = %s",#s1,s1,#s2,s2)
[ ... ] Quote: Quote:
>So in your case, if you write:
>>
> JOIN(str1, str2)
>>
>the replacement token would be:
>>
> printf("%s = %s %s = %s", "str1", str1, "str2", str2);
>
Not quite. It would be:
>
printf("%s = %s %s = %s","str1",str1,"str2",str2)
Yes! Quote:
The most important difference is, of course, that your semicolon is
spurious.
Indeed. I'd meant to write:
JOIN(str1, str2); |  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,392 network members.
|