Thread overview
Nasty -O bug
Jan 16, 2008
bobef
Jan 16, 2008
downs
Jan 16, 2008
bobef
Jan 17, 2008
Matti Niemenmaa
January 16, 2008
Consider this code:

Stdout(cast(int)p.button_state,(cast(int)p.button_state)>0?-48:48).newline.flush;

p.button_state is uint and when compiled with -O (DMD 1.025, Windows), it outputs something like this:

1, -48
-1, -48

Removing the -O flags makes it work.
Also this thing (no matter of the -O flag):

auto a=FOCUS_LOST|SINKING;
if(p.cmd==a) {...}

works, but not this:

if(p.cmd==FOCUS_LOST|SINKING) {...}

both FOCUS_LOST and SINKING are defined like this (in different enums):

enum MYENUM
{
  FOCUS_LOST=4,
  ...
}

alias MYENUM.FOCUS_LOST FOCUS_LOST;

This is really annoying...

Thanks,
bobef
January 16, 2008
bobef wrote:
> Also this thing (no matter of the -O flag):
> 
> auto a=FOCUS_LOST|SINKING;
> if(p.cmd==a) {...}
> 
> works, but not this:
> 
> if(p.cmd==FOCUS_LOST|SINKING) {...}
> 

Purely out of interest, could you try this:
> if (p.cmd == (FOCUS_LOST|SINKING))

 --downs
January 16, 2008
downs Wrote:

> bobef wrote:
> > Also this thing (no matter of the -O flag):
> > 
> > auto a=FOCUS_LOST|SINKING;
> > if(p.cmd==a) {...}
> > 
> > works, but not this:
> > 
> > if(p.cmd==FOCUS_LOST|SINKING) {...}
> > 
> 
> Purely out of interest, could you try this:
> > if (p.cmd == (FOCUS_LOST|SINKING))
> 
>  --downs

"if (p.cmd == (FOCUS_LOST|SINKING))" works.
January 17, 2008
bobef wrote:
> downs Wrote:
>> bobef wrote:
>>> Also this thing (no matter of the -O flag):
>>>
>>> auto a=FOCUS_LOST|SINKING;
>>> if(p.cmd==a) {...}
>>>
>>> works, but not this:
>>>
>>> if(p.cmd==FOCUS_LOST|SINKING) {...}
>>>
>> Purely out of interest, could you try this:
>>> if (p.cmd == (FOCUS_LOST|SINKING))
>>  --downs
> 
> "if (p.cmd == (FOCUS_LOST|SINKING))" works.

And it's meant to, and the other isn't, because the precedence of == is higher than the precedence of |.

IMHO it's stupid legacy, dating back to B (yes, B!), but what can you do.

-- 
E-mail address: matti.niemenmaa+news, domain is iki (DOT) fi