473,805 Members | 2,111 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

pls explain this macro

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

Jul 18 '07 #1
4 1715
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*********@gm ail.comwrote:
Message ID: <11************ **********@j4g2 000prf.googlegr oups.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*********@gm ail.comwrote:
Message ID: <11************ **********@j4g2 000prf.googlegr oups.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.in validwrote:
Message ID: <6f************ *********@bt.co m>
santosh said:
>On Wednesday 18 Jul 2007 1:53 pm, in comp.lang.c, Ravi
<ra*********@g mail.comwrote:
Message ID: <11************ **********@j4g2 000prf.googlegr oups.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
34288
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 capabilities, unfortunately. I'd like to know if it may be possible to add a powerful macro system to Python, while keeping its amazing syntax, and if it could be possible to add Pythonistic syntax to Lisp or Scheme, while keeping all of the...
13
2472
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 *lh_first; /* first element */
21
1650
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
1515
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
3156
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 interrupt.h and it should set a partilcular interrrupt. Thanks.
11
1907
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
1300
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 something to do with the position.
1
1990
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
1853
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
9596
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10614
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10109
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9186
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7649
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5544
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5678
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4327
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3847
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.