Yet another slap on the hand by implicit bool to int conversions

Andrej Mitrovic andrej.mitrovich at gmail.com
Sun Jun 19 14:32:38 PDT 2011


On 6/19/11, Vladimir Panteleev <vladimir at thecybershadow.net> wrote:
> On Sun, 19 Jun 2011 23:13:06 +0300, Andrej Mitrovic
> <andrej.mitrovich at gmail.com> wrote:
>
>> So I've had a pretty fun bug today when porting some code over to D.
>> When I port C code to D, first I do a one-to-one translation and make
>> sure everything works before I try to make use of any D features.
>
> How would you expect D to deal with types such as BOOL (which is a 32-bit
> type)?

I'm not sure what you're going for?

alias int BOOL;
enum : BOOL {
    FALSE = 0,
    TRUE  = 1
}

void main()
{
    bool value = getTrue();
}

BOOL getTrue()
{
    return TRUE;
}

Error: cannot implicitly convert expression (getTrue()) of type int to bool

My problem was implicit *D bool* conversion to D int types. Not the
windows bool type which is an int.


More information about the Digitalmars-d mailing list