Mail Archives: djgpp/2001/07/18/12:30:00
I have a question that's probably got nothing to with DJGPP, so please
forgive me for this off-topic post.
I tried the program below and interestingly, it gives me...
"Constant is 10. It is actually 1"
Shouldn't gcc not make the assumption that the value of j *is* 10 and
instead reference itfrom memory instead.
> Program:
>
> #include <iostream.h>
>
> class Test {
> public:
> static const int i;
>
> void run () { cout << i << endl; }
> Test () { }
> };
>
> const int Test::i = 7;
>
> const int j = 10;
>
> int main ()
> {
> Test t1;
> Test t2;
>
> int *k = (int *)&j;
> *k = 1;
> cout << "Constant is " << j << ". It is actually " << *k << endl;
> t1.run ();
> t2.run ();
> }
>
Thanks a lot for any explanations.
Regards,
Prashant
--
Prashant TR <tr AT midpec DOT com> Web: http://www.midpec.com/
"Those who do not understand Unix are condemned to reinvent it, poorly."
-- Henry Spencer
This message is confidential and may also be legally privileged. If you are not the intended recipient, please notify us immediately. You should not copy it or use it for any purpose, not disclose its contents to any other person. The views and opinions expressed in this e-mail message are the author's own and may not reflect the views and opinions of Wilco International
- Raw text -