digitalmars.D - Re: Transitive const sucks
- Alex Burton <alexibu mac.com> Sep 13 2007
Walter Bright Wrote:James Dennett wrote:Walter Bright wrote:Or you can cast away const-ness. But you are on your own if you do that.
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++.)
It's also undefined behavior if you cast a pointer to an int. You need to know what you're doing.
James point is still valid. If you cast away const in D whose powerful const system allows the compiler to do all sorts of optimisations, there is no way to know whether some of those optimisations are invalid with your cast. If you know what you are doing you can cast a pointer to an int with full knowledge that the logic of your program is ok.
Sep 13 2007