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

cpp: getting to the definition of a defined constant

The following code:

#define DEF3 DEF4
#define DEF2 DEF3
#define DEF1 DEF2
#define STRING(x) #x
#define SHOW(x) puts("#define " #x " " STRING(x))

void main () {
SHOW(DEF1);
SHOW(DEF2);
SHOW(DEF3);
SHOW(DEF4);
}

prints

#define DEF1 DEF4
#define DEF2 DEF4
#define DEF3 DEF4
#define DEF4 DEF4

what I want is to see that DEF1 is originally defined to DEF2.

Is there a way to get

#define DEF1 DEF2

printed, instead of

#define DEF1 DEF4

(i.e., I am getting the behavior of Lisp macroexpand,
while what I want is macroexpand-1 instead,
see http://www.lisp.org/HyperSpec/Body/f...oexpand-1.html)

Thanks!

PS. I also try to post to comp.lang.c.moderated,
but it does not appear there...

--
Sam Steingold (http://www.podval.org/~sds) running w2k
<http://www.memri.org/> <http://www.mideasttruth.com/> <http://truepeace.org>
<http://ffii.org/> <http://www.honestreporting.com> <http://www.dhimmi.com/>
If you're constantly being mistreated, you're cooperating with the treatment.
Nov 15 '05 #1
5 1377
Sam Steingold <sd*@gnu.org> wrote:

#define DEF1 DEF2

printed, instead of

#define DEF1 DEF4


No. C only allows no expansion at all or full expansion, it does not
provide any facility for just one level of expansion.

-Larry Jones

I hope Mom and Dad didn't rent out my room. -- Calvin
Nov 15 '05 #2
In article <nt************@jones.homeip.net>, <la************@ugs.com> wrote:
[with regard to C macro expansion]
No. C only allows no expansion at all or full expansion, it does not
provide any facility for just one level of expansion.


The # operator provides one level of expansion.

#define FOO(x) #x

This does NOT result in "x" such as would be the case if
"no expansion at all" were taking place.

The hard part is in expanding exactly -two- levels -- to get the
"first level replacement" associated with a parameter whose name
has been passed via a dummy argument.
--
I was very young in those days, but I was also rather dim.
-- Christopher Priest
Nov 15 '05 #3
> * Walter Roberson <eb******@voq.aep-paep.tp.pn> [2005-09-09 18:44:35 +0000]:

In article <nt************@jones.homeip.net>, <la************@ugs.com> wrote:
[with regard to C macro expansion]
No. C only allows no expansion at all or full expansion, it does not
provide any facility for just one level of expansion.


The # operator provides one level of expansion.

#define FOO(x) #x

This does NOT result in "x" such as would be the case if
"no expansion at all" were taking place.

The hard part is in expanding exactly -two- levels -- to get the
"first level replacement" associated with a parameter whose name
has been passed via a dummy argument.


OK, I could do with explicitly writing

#define Z(x) ((x)+(x))

puts("#define Z(y) " #Z(y));

to get "#define Z(y) ((y)+(y))" printed, but that does not work either.

--
Sam Steingold (http://www.podval.org/~sds) running w2k
<http://www.savegushkatif.org> <http://www.openvotingconsortium.org/>
<http://www.camera.org> <http://www.honestreporting.com> <http://truepeace.org>
Please wait, MS Windows are preparing the blue screen of death.
Nov 15 '05 #4
On Fri, 09 Sep 2005 13:28:11 -0400, Sam Steingold <sd*@gnu.org> wrote:

PS. I also try to post to comp.lang.c.moderated,
but it does not appear there...


You'll have to wait until the moderator posts it.
--
Al Balmer
Balmer Consulting
re************************@att.net
Nov 15 '05 #5
Walter Roberson <ro******@ibd.nrc-cnrc.gc.ca> wrote:

The # operator provides one level of expansion.

#define FOO(x) #x

This does NOT result in "x" such as would be the case if
"no expansion at all" were taking place.


That's argument substitution, not macro expansion.

-Larry Jones

What this games needs are negotiated settlements. -- Calvin
Nov 15 '05 #6

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

Similar topics

303
by: mike420 | last post by:
In the context of LATEX, some Pythonista asked what the big successes of Lisp were. I think there were at least three *big* successes. a. orbitz.com web site uses Lisp for algorithms, etc. b....
11
by: Steven T. Hatton | last post by:
I've made no secret of the fact that I really dislike the C preprocessor in C++. No aspect of the language has caused me more trouble. No aspect of the language has cause more code I've read to be...
61
by: Steven T. Hatton | last post by:
Stroustrup's view on classes, for the most part, seems to be centered around the notion of invariants. After a bit of adjusting to the use of yamt (yet another math term) in computer science, I...
14
by: Mike Hewson | last post by:
Have been researching as to why: <example 1> class ABC { static const float some_float = 3.3f; }; <end example 1>
8
by: Ignazio | last post by:
When creating forms with Visual C++ 2005, all the code for building the interface (the InitializeComponent method) and event handlers are set in the ..H file, as they were inline methods. So I ask,...
4
by: Belebele | last post by:
In a cpp file, say a.cpp I have the following code: #include <element.h> struct Functor { void operator (Element const& ) const { /* ... */ } }; /* ... */
7
by: Kristian Virkus | last post by:
Hello! I would like to write a C programm with multiple include files, where one may use another one (to print the value of a variable). When I try to compile the program below, the linker...
6
by: grbgooglefan | last post by:
I am compiling CPP program which uses CPython API functions from Python 2.5.1 source code First I compiled with this commanline, that time I got "pyconfig.h" not found. g++ -Os -I../../Include...
1
by: todWulff | last post by:
Good day folks. Let me open with the statement that I am not a C++/C programmer. The environment that I am programming in is ARMbasic, an embedded BASIC targeted toward ARM-based...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

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.