Error on negating unsigned types

Daniel Kozak via Digitalmars-d digitalmars-d at puremagic.com
Tue Jul 11 13:13:27 PDT 2017


I belive this is a bug or it should be fixed and do same as C does.

import std.stdio;

void main()
{
    uint total = 0;
    byte popCount() { return 5; }

    writeln(total + popCount() - popCount());
}

works as expected

On Tue, Jul 11, 2017 at 9:57 PM, Johan Engelen via Digitalmars-d <
digitalmars-d at puremagic.com> wrote:

> On Tuesday, 11 July 2017 at 19:46:00 UTC, Johan Engelen wrote:
>
>> The Weka folks would like to see a compile error on negating unsigned
>> types:
>>
>
> Also this nice hackery would need a workaround:
> ```
>    if ((y&(-y))==y)
> ```
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20170711/254b64dd/attachment.html>


More information about the Digitalmars-d mailing list