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

Carlos Santander csantander619 at gmail.com
Sun Jun 24 13:08:40 PDT 2007


James Dennett escribió:
> 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

But they're going to find it anyway. They'll read an error message, come here 
and ask what that means, someone will tell them to use cast(break const), and 
they'll be left wondering why the compiler couldn't tell that in the first 
place. Not only that, but after a while it'll become FAQ material.

I agree with your point, but not much will be gained in the end.

-- 
Carlos Santander Bernal



More information about the Digitalmars-d mailing list