size_t index=-1;

Basile B. via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Mar 19 03:37:15 PDT 2016


On Saturday, 19 March 2016 at 10:24:41 UTC, Ola Fosheim Grøstad 
wrote:
> On Saturday, 19 March 2016 at 10:01:41 UTC, Basile B. wrote:
>> On Saturday, 19 March 2016 at 09:33:25 UTC, tsbockman wrote:
>>> [...] The reason that *attempting* such a comparison produces 
>>> such weird results, is because the signed value is being 
>>> implicitly cast to an unsigned type.
>>
>> Yes and that's the opposite that should happend: when signed 
>> and unsigned are mixed in a comparison, the unsigned value 
>> should be implictly cast to a wider signed value. And then it 
>> works!
>>
>> - https://issues.dlang.org/show_bug.cgi?id=15805
>> - 
>> https://github.com/BBasile/iz/blob/v0.5.8/import/iz/sugar.d#L1017
>
> I have no problem with C++ compilers complaining about 
> signed/unsigned comparisons. It sometimes means you should 
> reconsider the comparison, so it leads to better code.
>
> The better solution is to add 7, 15, 31 and 63 bit unsigned 
> integer types that safely converts to signed (this is what Ada 
> does)

FPC (Object Pascal) too, but that not a surpise since it's in the 
same family

> and remove implicit conversion for unsigned 8,16,32, and 64 bit 
> integers.

Yes that's almost that but in D the only solution I see is like 
in my template: widening. When widening is not possible (mainly 
on X86_64) then warning. The problem is that cent and ucent are 
not implemented, otherwise it would always work even on 64 bit OS.

I'd like to propose  a PR for this (not for cent/ucent but for 
the widening) but it looks a bit overcomplicated for a first 
contrib in the compiler...


More information about the Digitalmars-d-learn mailing list