MrBean

outsmarted by the compiler again. (bug?)

Discussion created by MrBean on Jul 28, 2011
Latest reply on Aug 2, 2011 by MrBean
static unsigned long ArrayInIdx  =0;static unsigned long ArrayOutIdx =0;void test1(void) {   unsigned long idx = ArrayInIdx;      // get array index   if( -16L+idx-ArrayOutIdx >= 0 )      // not full ? (less than 16)      return;   ArrayInIdx++;                        // allocate array element}void test2(void) {   unsigned long idx = ArrayInIdx;      // get array index   if( idx-ArrayOutIdx >= 16L )         // not full ? (less than 16)      return;   ArrayInIdx++;                        // allocate array element}static signed long sArrayInIdx  =0;static signed long sArrayOutIdx =0;void test3(void) {   signed long idx = sArrayInIdx;        // get array index   if( -16L+idx-sArrayOutIdx >= 0 )      // not full ? (less than 16)      return;   sArrayInIdx++;                        // allocate array element}

 

 

 

The test1() function compiles to a single rts, ie. the compiler thinks the condition is always true.

The other two compile as intended.

 

Am i wrong to assume that the argument of the 'if' always is signed ?

Is the compiler messing up ?

 

 

( PS: CW7.2se )

Outcomes