Safer casts
terranium
spam at here.lot
Fri May 9 03:49:17 PDT 2008
Janice Caron Wrote:
> I note
> that the name is now less apt.
that's what I meant.
> > 3) I believe reinterpret_cast was introduced as analog of C cast,
>
> It was introduced to replace /one/ kind of transformation which
> old-style casts did, but not all of them. For example
>
> // C++
> double x;
> int y = reinterpret_cast<int>(x); // won't compile
> int y = static_cast<int>(x); // OK
>
> D already has cast for /all/ of the purposes I listed, so you could
> argue that D doesn't need any of them. The point is, if you wanted to
> be explicit about exactly what kind of transformation you wanted, then
> you would need it.
My opinion is we don't need to be explicit when casting double to int. reinterpret_cast is used usually to cast to/from void* - that is for pointer types - here it has no difference with D cast. Adding new construct adds complexity and requires extra time to learn and extra info to keep in mind, I believe these constructs' safeness is minor and it's not worth its complexity.
> I wasn't disputing that. Consider this a separate proposal.
I meant my proposal is better :))) We need only minor extra safeness. This can be achieved just by standardizing safe cast.
More information about the Digitalmars-d
mailing list