Constants, Aliases
Alexander Panek
a.panek at brainsware.org
Sat Dec 16 00:57:02 PST 2006
janderson wrote:
> Alexander Panek wrote:
>> Xinok wrote:
>>
>> Technically, you can change a constant value in C++, too, if you want.
>> Just get the address and write a little inline assembler to mov x, y
>> something else there. I can't imagine what'd hold me off from that.
>
> Actually that would be very difficult to make work, with optimisation.
> You'd have to find and replace every position the const was used
> (including ones that have been combined with other constants and
> optimizations) and replace them.
This depends on how you used const.
const uint x = 1; // this is your case, the variable is just set in and
has no unique memory address
class X {
const uint x;
this ( ) {
this.x = 0; // here, x has an address and const is meant to be a
write-once variable, not a constant value as above.
}
}
Alex
More information about the Digitalmars-d
mailing list