Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 09-18-2004, 09:01 PM   #1
Registered: Oct 2003
Posts: 203

Rep: Reputation: 30
global const int X = DEFINED (shows value in debugger?)

i read that if u #DEFINE a value u use, in a debugger, it'll show up with it's value and not it's name (so may be hard to identify from other values if they're the same)

but if u use const x = 10, u always see 10 as x (so u know what the reference is to.)

if i want to do the second thing and i've already got a #DEFINED var i want to use...
global const int X = SOME_HASH_DEFINED_VAR;
will i see X as 10, X as X or X as SOME_HASH_DEFINED_VAR (this last one won't occur, right?)

Old 09-18-2004, 09:24 PM   #2
Senior Member
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 58
#define'd constants are replaced by their value by the preprocessor, so the compiled binary never even knows the name. On the other hand, a global const value get its symbol (name) placed inside the compiled binary so the debugger can look it up.
Old 09-25-2004, 11:09 AM   #3
Registered: Oct 2003
Posts: 203

Original Poster
Rep: Reputation: 30
yeah i know, that's why i asked.

so X will get it's symbol looked up and reported back as 10, right? SOME_HASH_DEFINED_VAR gets replaced by 10 (doesn't exist) in the symbol list from that point on or after all the precompiler statements are executed?

i.e. i can change existing programs
#DEFINE OLDVAR VAL (prepend with 'OLD')
global const VAR = OLDVAR;

or undef the defined VAR and then define VAR as a global const. don't wanna do that coz it means i need to go to the place it's re-defined and enter it's value, or swap or whatever. this one provides all i need in one line.

and i can continue to change the value at the same place.

Last edited by abs; 09-25-2004 at 11:14 AM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
C++: #define OR const int ? Hady Programming 5 10-07-2005 11:43 AM
diff between #define and const defined variable b123coder Programming 7 06-27-2005 08:02 AM
can i modify int 80 vector to a user-defined vector qqrilxk Linux - Security 1 03-03-2005 08:46 PM
"int const" working problem. gpagedar Linux - General 0 10-08-2004 01:04 AM
c++ ERROR: int to const char ashirazi Programming 6 08-06-2004 10:01 PM

All times are GMT -5. The time now is 03:36 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration