DMD 1.019 and 2.003 releases

James Dennett jdennett at acm.org
Tue Jul 24 11:45:14 PDT 2007


Walter Bright wrote:
> 0ffh wrote:
>> So we get:
>>
>>   char +/- int  : okay
>>   int  +/- char : okay
>>   char  -  char : okay
>>   char  +  char : baddie!
>>
>> I Look at this this way: Nobody in his right mind is gonna
>> try to put into the compiler, which kinds of calculation
>> make "sense" and which don't; that would be just insane.
> 
> But I do things like:
> 
>     c += 'a' - 'A';   // to lower case

Which is fine according to the above rules: it uses char-char
(giving int, I hope), and then char+int (giving char, with
risk of overflow/wraparound in more general contexts but not
in this case).

> The problem with explicit casts is that they are a brute force method,
> and subvert static type checking. A well designed systems allows a
> balance between implicit casting and strong type checking so that
> explicit casts are rarely needed in properly written programs.

That's why I like the rules above.  They permit all sane
uses of arithmetic on characters while disallowing many
erroneous uses, and with no need for casts.

Not that I'm actually seriously suggesting changing D in
this direction.  This just isn't worth going against what
most programmers with C/C++/Java-like backgrounds expect.

-- James



More information about the Digitalmars-d-announce mailing list