Interested in D, spec confuses me.

Bambi via Digitalmars-d digitalmars-d at puremagic.com
Wed Feb 3 12:30:01 PST 2016


On Wednesday, 3 February 2016 at 12:12:03 UTC, Kagamin wrote:
> Immutability provides stronger guarantee that allows more 
> optimizations, e.g. reading the same immutable value is known 
> to result in the same value so such repeated reading can be 
> optimized out, in C such optimization is illegal, because const 
> data can change over time.

In C, you can only make pointers to const data a const pointer. 
The guarantee is built in there. Sure you can cast the address of 
a const to a regular pointer but then you are kind of going out 
of your way to break the rules and deliberately shoot yourself in 
the foot. I'm pretty sure casting away a const pointer to a const 
value is undefined behaviour.


More information about the Digitalmars-d mailing list