siddhu said:
I guess removing constness of a true const( I guess it is also called
bitwise const ) using const_cast is undefined behavior. Can you
please give an example of a true const and may be a sample code which
exhibits undefined behavior by removing constness of a true const.
Some folks here mentioned literals like double or int literals. But those
are not const, and const cannot meaningfully applied to them.
What "const" means is that the stored value of an object does not change
from one to another value. Changing the object may change the stored value
to something else. "const" prevents such changes to the object.
A value in and of itself does not convey a meaning of "const". Hence, in
C++, non-class and non-array rvalues cannot be const qualified. That makes a
great deal of sense, because they are not objects.
It should be mentioned that the C++ Standard does not know a strict
distinction between "value" and "object". In my text above, I used "value"
in the sense of "the abstract meaning designated by an object's value
representation", as defined by 3.9p4 (sadly that definition of "value" isn't
used consistently throughout the spec or draft).