Interested in D, spec confuses me.
Era Scarecrow via Digitalmars-d
digitalmars-d at puremagic.com
Thu Feb 4 00:16:56 PST 2016
On Thursday, 4 February 2016 at 06:34:15 UTC, Kagamin wrote:
> On Wednesday, 3 February 2016 at 20:30:01 UTC, Bambi wrote:
>> I'm pretty sure casting away a const pointer to a const value
>> is undefined behaviour.
>
> const data in C can be immutable, but also can be mutable and
> change over time, that's why immutable optimizations are
> illegal on it: you can't tell if it's immutable, the const
> qualifier tells nothing about that, it only helps the callee to
> not modify the data.
I tend to take away the meanings in D:
Immutable: This data Cannot/Will not change
Const: I promise not to change your data on you (but the owner
might make changes to it at some point)
So converting a const pointer to a const value... it still
remains const (and it's value doesn't/won't change if const is
honored). You could throw away the constness; This assumes that
it doesn't have referenced data/pointers and you're editing only
a local copy (or duplicated it first); But that's it's own thing
to discuss.
More information about the Digitalmars-d
mailing list