safer casts - take II

Paul D. Anderson paul.d.removethis.anderson at comcast.andthis.net
Tue May 13 10:39:37 PDT 2008


Yigal Chripun Wrote:

> 
> there are there forms of cast:
> (a) cast(T)something
> (b) cast!(T)something
> (c) reinterpret_cast!(T)
> 

> questions?

My only concern is the re-use of '!'.

My first thought on reading your proposal was that 'cast!(T)' was some sort of template. I'm sure with a little practice I could get to where I immediately recognize it as a dangerous(!) cast, but it's just one more thing to learn.

>From my cursory examination of keyword usage I've concluded that the keywords that are problematic ('const', 'enum') are the ones that mean different (but related) things in different usages. I'm not at all convinced that parsimony in keywords is a good thing, but that seems to be a minority view (and it isn't Walter's view, as far as I can tell).

We're a little more accustomed to re-definition of symbols, especially in a new context, but this isn't new -- it's a variable name followed by a '!'.

Having said that, I don't have an alternative notation. Perhaps a long keyword llike 'const_cast', 'invariant_cast', etc., similar to the 'reinterpret_cast' usage.

I do think it's a good idea, though to have the separate types of casts called out.

Paul



More information about the Digitalmars-d mailing list