digitalmars.D.bugs - Nasty -O bug
- bobef (21/21) Jan 16 2008 Consider this code:
 - downs (3/13) Jan 16 2008 --downs
 - bobef (2/17) Jan 16 2008 "if (p.cmd == (FOCUS_LOST|SINKING))" works.
 - Matti Niemenmaa (6/22) Jan 17 2008 And it's meant to, and the other isn't, because the precedence of == is ...
 
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
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
downs Wrote:bobef wrote:"if (p.cmd == (FOCUS_LOST|SINKING))" works.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
bobef wrote:downs Wrote: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) fibobef wrote:"if (p.cmd == (FOCUS_LOST|SINKING))" works.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 17 2008








 
 
 
 Matti Niemenmaa <see_signature for.real.address>