473,246 Members | 1,446 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,246 software developers and data experts.

pls explain this macro

#define JOIN(s1,s2) printf("%s = %s %s = %s",#s1,s1,#s2,s2)

Jul 18 '07 #1
4 1696
Ravi wrote:
#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.
Jul 18 '07 #2
On Wednesday 18 Jul 2007 1:53 pm, in comp.lang.c, Ravi
<ra*********@gmail.comwrote:
Message ID: <11**********************@j4g2000prf.googlegroups. com>
#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);
Jul 18 '07 #3
santosh said:
On Wednesday 18 Jul 2007 1:53 pm, in comp.lang.c, Ravi
<ra*********@gmail.comwrote:
Message ID: <11**********************@j4g2000prf.googlegroups. com>
>#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
Jul 18 '07 #4
On Wednesday 18 Jul 2007 3:12 pm, in comp.lang.c, Richard Heathfield
<rj*@see.sig.invalidwrote:
Message ID: <6f*********************@bt.com>
santosh said:
>On Wednesday 18 Jul 2007 1:53 pm, in comp.lang.c, Ravi
<ra*********@gmail.comwrote:
Message ID: <11**********************@j4g2000prf.googlegroups. com>
>>#define JOIN(s1,s2) printf("%s = %s %s = %s",#s1,s1,#s2,s2)
[ ... ]
>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!
The most important difference is, of course, that your semicolon is
spurious.
Indeed. I'd meant to write:

JOIN(str1, str2);
Jul 18 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

699
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro...
13
by: C++fan | last post by:
The following code is for list operation. But I can not understand. Could anyone explain the code for me? /* * List definitions. */ #define LIST_HEAD(name, type) struct name { type...
21
by: Gactimus | last post by:
Can anyone explain what the lines with the '*' by them do? ----------- #ifndef _COUNTER_H #define _COUNTER_H #include <iostream> using namespace std; class Counter
2
by: Ravi Uday | last post by:
Hi, Can anybody explain this.. #define LIST_DESTROY(a) list_destroy(a) #define LIST_ENQUEUE(a, b, c) list_enqueue(a,b,c) #define LIST_REMOVE(a, b, c) list_remove(a,b,c) etc...
6
by: Affan Syed | last post by:
I am not able to figure out exactly what this macro is doing. Can one of the gurus around here decipher this? #define sei() __asm__ __volatile__ ("sei" ::) PS: It is from the avr-libc...
11
by: kartheeknagasuri | last post by:
my friend gave this code to me..... it is working fine....how come? please explain me if u can understand..... #include <stdio.h> #include <conio.h> #define _(__,___)\ ___##__
2
by: TYF | last post by:
hi, can any one explain me what this little macro is doing? #define pos_of(h, f) ((short int) &((h *) 0)->f) h is a struct f is a member of it i have no clue, i only know it has...
1
by: zhangyefei.yefei | last post by:
#define cat(x,y) x##y concatenates x to y. But cat(cat(1,2),3) does not expand but gives preprocessor warning. Why? thanks .
12
by: webinfinite | last post by:
#define D(y...) (const int ) {y} My understand is that D is taking in a various length parameter y which is an array of const int. Am I right? Thanks.
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.