473,395 Members | 1,403 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,395 software developers and data experts.

Quoting symbol in CPP

Given this:

#define NUM 100

I was to use a CPP macro like:

char *p = MACRO(NUM);

and have MACRO defined such that it would expand to:

char *p = "100";

I tried:

#define MACRO(X) #X

but, for MACRO(NUM), that expands to:

char *p = "NUM";

How can I get CPP to expand NUM first?

- Paul
Jun 27 '08 #1
2 1354
On May 9, 10:26*pm, "Paul J. Lucas" <paul-nos...@nospam.lucasmail.org>
wrote:
Given this:

* * * * #define NUM 100

I was to use a CPP macro like:

* * * * char *p = MACRO(NUM);

and have MACRO defined such that it would expand to:

* * * * char *p = "100";

I tried:

* * * * #define MACRO(X) #X

but, for MACRO(NUM), that expands to:

* * * * char *p = "NUM";

How can I get CPP to expand NUM first?

- Paul
The preprocessor will expand the macro parameters first, unless
they appear next to a # (or ##).
So try this:

#define NUM 100
#define MACRO(X) #X
#define GOODMACRO(X) MACRO(X)

char *p=GOODMACRO(NUM);

GOODMACRO's argument is not following an #, so it is expanded, prior
to
looking at MACRO's meaning.

Szabolcs
Jun 27 '08 #2
On May 10, 12:26 am, "Paul J. Lucas" <paul-
nos...@nospam.lucasmail.orgwrote:
Given this:

#define NUM 100

I was to use a CPP macro like:

char *p = MACRO(NUM);

and have MACRO defined such that it would expand to:

char *p = "100";

I tried:

#define MACRO(X) #X

but, for MACRO(NUM), that expands to:

char *p = "NUM";
Question 11.17 of the C-faq.
<http://c-faq.com/>
Jun 27 '08 #3

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

Similar topics

0
by: Richard | last post by:
I am setting up HS in 8i, when I go to $ORACLE_HOME/bin and do a ldd hsodbc i get the below error message, I have done a relink to recreate the hsodbc executable but still no luck. I do have a tar...
22
by: Jane Withnolastname | last post by:
I have been using the charset windows-1252 for a while, but it was pointed out to someone else in this group recently that it's a Microsoft creation (I'm sure I'm getting my facts wrong or skewed)...
383
by: John Bailo | last post by:
The war of the OSes was won a long time ago. Unix has always been, and will continue to be, the Server OS in the form of Linux. Microsoft struggled mightily to win that battle -- creating a...
27
by: Ron Adam | last post by:
Hi, I found the following to be a useful way to access arguments after they are passed to a function that collects them with **kwds. class namespace(dict): def __getattr__(self, name): return...
1
by: vsp15584 | last post by:
Hii..i use the coding as below :- import java.applet.applet; import java.awt.*; import com.sun.j3d.utils.applet.mainframe; import com.sun.j3d.utils.universe.*; import...
2
by: f rom | last post by:
----- Forwarded Message ---- From: Josiah Carlson <jcarlson@uci.edu> To: f rom <etaoinbe@yahoo.com>; wxpython-users@lists.wxwidgets.org Sent: Monday, December 4, 2006 10:03:28 PM Subject: Re: ...
6
by: sadegh | last post by:
Hi I have a problem with my program in VC++6 When I compile it, the following errors are listed. I spend a lot of time on the groups.google.com to find its reason, but none of comments could...
7
by: Steven W. Orr | last post by:
Python has a number of "quoting" 'options' to help """with times when""" one way may be more convenient than another. In the world of shell scripting, I use a technique that I call minimal...
0
by: Ryan Gaffuri | last post by:
hlink72@hotmail.com (Eric) wrote in message news:<ab8d8b14.0308220550.54fb5f22@posting.google.com>... LNK1120 is a standard C++ error. you using Visual C++? Means your references a class that...
3
by: Sindhu Rani | last post by:
i hav created 3 classes in 3 different files. am gettin an error durin compilation. wat shud i do??? C:\s\source>javac -d ..\classes devtestdrive.java devtestdrive.java:5: cannot resolve symbol...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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...

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.