Transitive const sucks

Mike Capp mike.capp at gmail.com
Thu Sep 13 12:51:32 PDT 2007


James Dennett Wrote:

> Well, in C++ you'd be fine, but in D I thought the behavior
> if you modified something after casting away const was
> undefined, so you're out of luck.  (Not that you'd need
> to cast away const for this in C++.)

You'll hit undefined behavior in C++ as well if the data being modified (via a const_cast) was originally declared as const. Compilers can (and some PPC compilers did) put such data in read-only memory, and even if they don't they tend to assume "really, truly const" and optimize accordingly. Hours of fun for all the family.

cheers
Mike



More information about the Digitalmars-d mailing list