473,657 Members | 2,358 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2210
>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 "effectivel y." 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.


<Implementati on 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
25420
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 !defined(var) construct is returning true. I am using gcc3.0.1 on SunOS8. I would appreciate if any body can tell me whether this is a bug or I am doing something wrong. tia, Srinivas
8
7890
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 /db2inst1/NODE0000/SQL00002 /db2inst1/NODE0000/SQL00003 /db2inst1/NODE0000/SQL00004
1
4443
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. Directory.GetCurrentDirectory() returns working directory. Any solutions ? Dani
0
2492
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: StringCollection propNames = new StringCollection(); ManagementClass driveClass = new ManagementClass("Win32_DiskDrive"); PropertyDataCollection props = driveClass.Properties; foreach (PropertyData driveProperty in props) { propNames.Add(driveProperty.Name);
7
24147
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: StringCollection propNames = new StringCollection(); ManagementClass driveClass = new ManagementClass("Win32_DiskDrive"); PropertyDataCollection props = driveClass.Properties; foreach (PropertyData driveProperty in props) { propNames.Add(driveProperty.Name);
1
3319
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
2005
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 ideally the state and/or city name. Thanks
1
2731
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 using string rootPath = Path.GetDirectoryName(System.Refelection.Assmebly.GetExecutingAssembly().Location); but the problem it returned a path in temprary folder in /winnt/framework/ver/temporay asp.net files ..i do not know why?
2
9427
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 some time my application got crashed and windows popped up a window asking for debug, send error report. 3. Clicking on Debug opens my workspace in .Net IDE.
0
8411
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8323
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
8739
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8613
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...
1
6176
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
4173
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
4329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2740
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
1732
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.