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

Physical Location of #define Symbols

Whilst reading through the C++ FAQ. I came across Section 29.8 and
realized I never had fully thought about where a #define resided in a
Standard C++ program.

I thought they were a compile-time entity where the preprocessor
"searched and replaced" the "symbol" with the literal value that had
been assigned with the #define.

From the FAQ, Section 29.8
<quote>
Every #define macro effectively creates a new keyword in every source
file and every scope until that symbol is #undefd. The preprocessor
lets you create a #define symbol that is always replaced independent
of the {...} scope where that symbol appears.
</quote>

Is this only at compile time? Are all #defines put into a global
symbol table? Or... ?

I guess I've been working from a "rote mode" all these years in regard
to #defines. (Which are evil.) :-)

PS: I tried many search term permutations in Google with this and
literally none were less than 2 million hits. Too much can be the
same as none at all. :-)

Thanks in advance.
Jan 16 '06 #1
7 2193
>Is this only at compile time? Are all #defines put into a global
symbol table? Or... ?


IIRC #define does not go into the symbol table. Something I read along
these lines in Effecive C++ by Scott Meyers. You can't dereference a
defined name. The pre processor replaces every #define with something
it likes or prefers.

Jan 16 '06 #2
TB
Shark sade:
Is this only at compile time? Are all #defines put into a global
symbol table? Or... ?


IIRC #define does not go into the symbol table. Something I read along
these lines in Effecive C++ by Scott Meyers. You can't dereference a
defined name. The pre processor replaces every #define with something
it likes or prefers.


After lexical translation phase 4, #define symbols are no longer needed,
and can be discarded.

--
TB @ SWEDEN
Jan 16 '06 #3
Shark wrote:
Is this only at compile time? Are all #defines put into a global
symbol table? Or... ?


IIRC #define does not go into the symbol table. Something I read along
these lines in Effecive C++ by Scott Meyers. You can't dereference a
defined name. The pre processor replaces every #define with something
it likes or prefers.


The preprocessor does text substitution, and then it's output is passed
to the compiler. No symbols are retained. So, for instance, all
#include statements are replaced with the contents of the specified
file, and all #defines are substituted whenever the specified token is
found. Every compiler I've used has had a switch to output the
preprocessed file that would be passed to the compiler so that the
programmer can verify exactly what substitutions took place.

Cheers! --M

Jan 16 '06 #4
JustBoo wrote:
Whilst reading through the C++ FAQ. I came across Section 29.8 and
realized I never had fully thought about where a #define resided in a
Standard C++ program.

I thought they were a compile-time entity where the preprocessor
"searched and replaced" the "symbol" with the literal value that had
been assigned with the #define.
I believe that is essentially correct - the preprocessor engages in
simple textual substitution.

From the FAQ, Section 29.8
<quote>
Every #define macro effectively creates a new keyword in every source
file and every scope until that symbol is #undefd. The preprocessor
lets you create a #define symbol that is always replaced independent
of the {...} scope where that symbol appears.
</quote>
I think the key word in the above quotation is "effectively." Every
define macro _effectively_ creates a new keyword ... independent of the
{...} scope where the symbol appears.
Is this only at compile time? Are all #defines put into a global
symbol table? Or... ?


Only at compile time.

Best regards,

Tom

Jan 16 '06 #5
On 16 Jan 2006 14:01:11 -0800, "Thomas Tutone"
<Th***********@yahoo.com> wrote:
JustBoo wrote:
I thought they were a compile-time entity where the preprocessor
"searched and replaced" the "symbol" with the literal value that had
been assigned with the #define.


I believe that is essentially correct - the preprocessor engages in
simple textual substitution.


Okay, from your response and others I can rest easy. :-)

As I though, the compiler holds/saves the "symbols" during the
preprocessor phase, uses them, then releases them when done.
All during compile time.

To mlimber: Got it. :-) In the good ol' bad ol' days when I first
learned C++ with Borland's TurboC++ I remember there was an
option on a main menu dropdown that allowed one to view the
preprocessor output. It was quite instructive.

I don't remember it being such a prominent feature on any other
compiler since.

Thanks to all who responded.
--
Not all those who wander are lost. - J.R.R. Tolkien
Jan 17 '06 #6
JustBoo wrote:
To mlimber: Got it. :-) In the good ol' bad ol' days when I first
learned C++ with Borland's TurboC++ I remember there was an
option on a main menu dropdown that allowed one to view the
preprocessor output. It was quite instructive.

I don't remember it being such a prominent feature on any other
compiler since.


<Implementation Specific>

Not sure if this is what you are referring to, but using gcc (and I
imagine most other compilers), one can run the preprocessor without
compiling the resulting code. In other words, ordinarily when one
compiles, what actually happens is the preprocessor first preprocesses
the code (brings in any #include files, strips out the comments, makes
the #define substitutions, etc.), then feeds the result into the
compiler. On gcc, one can call the preprocessor by itself by executing
cpp (rather than gcc or g++) at the command line. Looking at the
result can be very instructive, since it now reflects the result of all
the macro substitution. The result also tends to be very long if your
file #include's any system headers.

Of course, you might not characterize that feature as being as
"prominent" as it was on TurboC++

</Implementation Specific>

Best regards,

Tom

Jan 17 '06 #7
On 16 Jan 2006 16:12:41 -0800, "Thomas Tutone"
<Th***********@yahoo.com> wrote:

[snipped good explanation]
Of course, you might not characterize that feature as being as
"prominent" as it was on TurboC++


And you would be correct. :-) Not being as easy to use I don't use it
as much. "No excuse!" I know....

However beautiful the strategy, you should occasionally
look at the results. - Winston Churchill <grin>
Jan 17 '06 #8

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

Similar topics

20
by: srinivas reddy | last post by:
I have defined some variables using #define preprocessor instruction. And then later I checked whether I had defined a variable. Sometimes even though a variable have been defined, #if...
8
by: Kamlesh | last post by:
Hi, How do I know the physical database path of a database. When I goto the DB2INSTANCE users's directory (/home/db2inst1), I see following folders: /db2inst1/NODE0000/SQL00001...
1
by: Dani Peer | last post by:
Hi, I build a COM interop DLL. I want that this dll will be able to get it's PHYSICAL LOCATION since I need it to read an XML file. How can I get the Physical location....
0
by: john doe | last post by:
How can I use WMI or a WqlObjectQuery to find the hard drive letter of the physical drive location index. For example the following code will give me the physical drive location:...
7
by: jimdscudder | last post by:
How can I use WMI or a WqlObjectQuery to find the hard drive letter of the physical drive location index. For example the following code will give me the physical drive location:...
1
by: A.M-SG | last post by:
Hi, We have a solution with several c# projects within it. How can I define solution wide conditional compilation symbols?
4
by: Verde | last post by:
I know this is somewhat OT, but don't know where else to ask: How can I discover the rough physical location of an IP address? By "rough physical location" I'm thinking at least country, and...
1
by: Raed Sawalha | last post by:
I have a problem in getting asp.net application physical path in global.ascx static function in my global.ascx i have a static function : first i tried to get the physical path by refelection...
2
by: bhreddy | last post by:
Hi All, Can someone help me out how can I resolve the error "0xC0000005: Access violation reading location 0x513112f4"? Steps I followed... 1. I ran the application at DOS prompt 2. After...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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
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...

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.