View Single Post
  #6 (permalink)  
Old 10-29-2005, 01:10 PM
syntetic@mail.ru
Guest
 
Posts: n/a
Default Re: const usage in c++

> const int i = 100;
> int *p = (int *)&i;
> *p = 200;


> Modifying a true constant is undefined behavior.


Hello, All.

Just one more question, what about volatile keyword?
Can I do something like:

volatile const int i = 100;
int * = (int*)&i;
*p = 200;
std::cout << i;

I try this example under VC7.0 and receive the same result.
Is this undefined behavior or compler bug?

With respect,
Alexander Kozlov


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Reply With Quote