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

torhu fake at address.dude
Sun Jun 24 17:09:32 PDT 2007


Carlos Santander wrote:
> 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.
> 

What if the error message is something like 'can't assign const int* b 
to non-const int* d'?  If they really want a const cast, they'll then go 
look at the docs for cast expressions to see why it didn't work. 
Otherwise, they'll try making d a const.



More information about the Digitalmars-d mailing list