www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - Nasty -O bug

reply bobef <bobef abv-nospam.bg> writes:
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
Jan 16 2008
parent reply downs <default_357-line yahoo.de> writes:
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
Jan 16 2008
parent reply bobef <bobef abv-nospam.bg> writes:
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.
Jan 16 2008
parent Matti Niemenmaa <see_signature for.real.address> writes:
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
Jan 17 2008