D2.0: an example of use-case for casting invariant away

James Dennett jdennett at acm.org
Sun Jun 24 09:33:55 PDT 2007


Jason House wrote:
> Don Clugston wrote:
>> int* d = cast(break const) b;
>>
>> IMHO, we want something that looks really nasty.
> 
> Based on all the discussion in this thread, I like this alternative
> best.  I'd only insist that if someone did int *d = cast(int*) b; that
> the compiler would issue an error saying to use cast(break const) instead

Interesting: my experience suggests that it shouldn't do so.
Those who know enough to use cast(break const) appropriately
will find out how to do so.  Others would just read the error
message and blindly do what it said, pausing only briefly to
wonder why the compiler issued an error message if it knew
exactly how to "fix" the code.  Far too many programmers'
first reaction to type warnings/errors is to add casts and
mask the problem rather than addressing root cause.

-- James



More information about the Digitalmars-d mailing list