DMD 1.019 and 2.003 releases

James Dennett jdennett at acm.org
Tue Jul 24 11:41:38 PDT 2007


Derek Parnell wrote:
> On Mon, 23 Jul 2007 21:25:31 -0700, James Dennett wrote:
> 
>> BCS wrote:
>>> Reply to Derek,
>>>
>>>> Are you serious??? Why are we allowed to do mathematics with
>>>> characters?
>>>>
>>> I have done this a few times
>>>
>>> char c;
>>> int v = (c - '0')
>> Perfectly reasonable, as is character +/- integer, but
>> character + character is nonsense, just as it makes sense
>> to subtract two points yielding a vector, or add a vector
>> to a point (yielding a point) but no sense to "add" two
>> points in a mere affine space.
> 
> I'm sorry. I am a bit of a pedantic bastard at times. 

You're in good company.

> I use ...
> 
>  char c;
>  int v = (cast(int)c - '0')
> 
> To me it the same as assuming that boolean values are integers.

Subtracting a char from an int, as you appear to be doing
above, also makes no sense... or do casts in D bind insanely
loosely?  Subtracting one char from another actually makes
more sense (see analogy above to affine geometry).  It's a
reasonable question to ask "which offset must I add to this
char to get to this other char", but not "what's the difference
between the number 27 and the character 'o'?".

(And yes, I feel guilty/contaminated if I ever treat a boolean
value as an integer, or vice versa.)

-- James



More information about the Digitalmars-d-announce mailing list