unsigned policy (implicit conversions for complex?)
Derek Parnell
derek at nomail.afraid.org
Mon Feb 12 18:56:26 PST 2007
On Mon, 12 Feb 2007 18:14:50 -0800, Andrei Alexandrescu (See Website For
Email) wrote:
> Derek Parnell wrote:
>> On Mon, 12 Feb 2007 16:03:14 -0800, Andrei Alexandrescu (See Website For
>> Email) wrote:
>>
>>> http://erdani.org/d-implicit-conversions.pdf
>>
>>> Did I forget something?
>>
>> Characters are not numbers.
>
> http://www.digitalmars.com/d/type.html specifies they are "unsigned" and
> also the number of bits. Their default initial value is written in hex.
> This made me assume that they can be treated as numbers.
I was trying not to confuse implementation with theory. D implements
characters using unsigned integers, but as they are not semantically
numbers, it makes no sense to do many numerical operations on characters;
such as adding or multiplying them. To allow them to be /implicitly/
converted to integers may lead to subtle bugs, as the compiler will miss
semantically incorrect usage.
int add(int a, int b)
{
return a + b;
}
int d = add('a', 'z'); // Should not match signature, but does.
--
Derek
(skype: derek.j.parnell)
Melbourne, Australia
"Justice for David Hicks!"
13/02/2007 1:49:57 PM
More information about the Digitalmars-d
mailing list