473,397 Members | 2,099 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,397 software developers and data experts.

How to use # & ## operator in C??

Hi Guys,
Do you know how to use # & ## operator in C?

For example, what's meaning for following code?

#define macro(a) #a

Jul 24 '06 #1
4 1234
gu ming said:
Hi Guys,
Do you know how to use # & ## operator in C?

For example, what's meaning for following code?

#define macro(a) #a
"The C Programming Language", 2nd edition, by Kernighan and Ritchie, page
90, from about half-way down the page, right down to the bottom.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Jul 24 '06 #2
Richard Heathfield wrote:
gu ming said:
Do you know how to use # & ## operator in C?
For example, what's meaning for following code?
#define macro(a) #a

"The C Programming Language", 2nd edition, by Kernighan and Ritchie, page
90, from about half-way down the page, right down to the bottom.
I'm surprised Steve Summit's online course notes don't get quite as
much airplay
as his FAQ...

http://c-faq.com/~scs/cclass/
http://c-faq.com/~scs/cclass/int/sx6a.html

--
Peter

Jul 24 '06 #3
Peter Nilsson wrote:
Richard Heathfield wrote:
gu ming said:
Do you know how to use # & ## operator in C?
For example, what's meaning for following code?
#define macro(a) #a
"The C Programming Language", 2nd edition, by Kernighan and Ritchie, page
90, from about half-way down the page, right down to the bottom.

I'm surprised Steve Summit's online course notes don't get quite as
much airplay
as his FAQ...

http://c-faq.com/~scs/cclass/
http://c-faq.com/~scs/cclass/int/sx6a.html
The link http://c-faq.com/~scs/cclass/int/sx6a.html does not mention
the # and ## operators. Otherwise the course is excellent.

Jul 24 '06 #4
On 23 Jul 2006 20:26:09 -0700, "gu ming" <gu******@gmail.comwrote:
>Hi Guys,
Do you know how to use # & ## operator in C?

For example, what's meaning for following code?

#define macro(a) #a

# can be used for turning an identifier into a string and ## can be
used to create an identifier from a macro's arguments, although I find
## hurts more than it helps. Once a set of code get's large enough,
## starts to make it harder to understand because the names of the
generated variables and functions can no longer be searched for as
easily. They're hidden behind macros.
#include <stdio.h>
#define PRINT_INT(x) \
do { printf("value of %s: %d\n", #x, x); } while(0)

#define CALL_FUNC(x) do { Func##x(); } while(0)
void FuncRead()
{
printf("Entered FuncRead\n");
}
void FuncWrite()
{
printf("Entered FuncWrite\n");
}
int main()
{
int my_variable = 57;

PRINT_INT(my_variable);
CALL_FUNC(Read);
CALL_FUNC(Write);

return 0;
}

Jul 25 '06 #5

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

Similar topics

1
by: learning_C++ | last post by:
Hi, I compiled some code. In the function friend ostream& operator<<(ostream& os, const complex c); I use the later argument complex c and complex& c. I can get the same values and there is no...
8
by: Jef Driesen | last post by:
I'm implementing some image processing algorithms in C++. I created a class called 'image' (see declaration below), that will take care of the memory allocations and some basic (mathematical)...
4
by: Luklrc | last post by:
Hi, I'm having to create a querysting with javascript. My problem is that javscript turns the "&" characher into "&amp;" when it gets used as a querystring in the url EG: ...
20
by: Vivek N | last post by:
Hi Folks, This question may well have been asked and answered before. But, sorry that I couldn't find one from the archives. I typed up this program and compiled it with gcc 3.3.2 main() { int...
21
by: siliconwafer | last post by:
Hi, In case of following expression: c = a && --b; if a is 0,b is not evaluated and c directly becomes 0. Does this mean that && operator is given a higher precedence over '--'operator? as...
17
by: orekinbck | last post by:
Hi There Say I want to check if object1.Property1 is equal to a value, but object1 could be null. At the moment I have code like this: if (object1 != null) { if (object1.Property ==...
6
by: Geoffrey S. Knauth | last post by:
It's been a while since I programmed in C++, and the language sure has changed. Usually I can figure out why something no longer compiles, but this time I'm stumped. A friend has a problem he...
8
by: Nathan Sokalski | last post by:
I add a JavaScript event handler to some of my Webcontrols using the Attributes.Add() method as follows: Dim jscode as String = "return (event.keyCode>=65&&event.keyCode<=90);"...
3
by: Nindi73 | last post by:
Hi, I am in need of a deep copy smart pointer (Boost doesn't provide one) which doesnt require the contained types to have a virtual copy constructor. I wrote a smart pointer class that I think...
1
by: developereo | last post by:
Hi folks, Can somebodyshed some light on this problem? class Interface { protected: Interface() { ...} virtual ~Interface() { ... } public:
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
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,...

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.