dmd 1.046 and 2.031 releases

Derek Parnell derek at psych.ward
Mon Jul 6 12:14:29 PDT 2009


On Mon, 06 Jul 2009 11:02:12 -0700, Walter Bright wrote:

> Derek Parnell wrote:
>> Safety is supposed to be enhance by using D, is it not?
> 
> See my post to Denis. Requiring too many casts reduces safety by 
> essentially disabling the static type checking system.

I totaly agree that cast() should be avoided, almost at all costs. A better
way in this situation is to use a variable that can accommodate the range
of possible values. Only use the cast() construct if you are deliberately
doing something other than normal.

For example, if you know that the different between two addresses will
always be less than a 16-bit value AND you are deliberately storing the
difference in a 'short' then using a cast() is a good idea as it alerts the
code reader to this unusual situation.

   short x = cast(short)(p1 - p2);

However, 

   auto x = p1 - p2;

should imply that 'x' is able to hold any value from -(uintptr_t.max) to
uintptr_t.max inclusive.

-- 
Derek Parnell
Melbourne, Australia
skype: derek.j.parnell


More information about the Digitalmars-d-announce mailing list