"Eric" <answer.to.newsgroup@nospam.com> wrote in message
news:i25ll4ljrb8lpnavhdom8a0nbqs7lb9gga@4ax.com...
On Tue, 30 Dec 2008 16:23:35 -0500, "Bill" <Bill_NOSPAM@comcast.net>
wrote:
No one mentioned (I think) that #define is a "pre-processor directive".
The substitution of "4" for "foo" is made before the "real compilation"
even
starts. Hence, no bytes for foo!
Good afternoon, Bill.
Right, I knew that (#define doesn't allocate memory). Just wasn't
sure if most optimizing compilers did the same with const int foo.
I few months ago I was experimenting with the latest MS VC++ compiler
(default settings).
I used a pointer and const_cast to change the value of a const int foo=5,
say to the value 7. The program continued to use the value 5 for foo,
except when I accessed the value of foo via the pointer, then the value was
7. Hence, I deduced, memory was allocated for foo, but the compiler
"optimized away" dynamic references to it. Consider trying it youself and
sharing what happens!
provided that you do not take the address of the constant.