As many people pointed out, the debugger can display interesting 
results with optimizations turned on, and that could very well be the 
source of the problem.

However, I _have_ seen a similar problem in the past, where the 
compiler was indeed generating incorrect code (skipping the entire 
code block) for a simple if/else statement with the optimization 
level set to 1. This was with an older version of CodeWarrior, so I 
don't know if it still happens with v2.3.2 of the C/C++ compiler. 
What version are you using?

I'd use CodeWarrior to generate a 68K disassembly of the routine with 
opt=1, and see if the 68K instructions are actually getting 
generated. If you want, email the dump to me.

-- Ken

At 12:00am -0700 00-08-17, Palm Developer Forum digest wrote:
>Subject: Attn: MetroWorks CW,  Annoying optimization issue
>From: "Charles Rezsonya" <[EMAIL PROTECTED]>
>Date: Mon, 14 Aug 2000 14:48:50 -0400
>X-Message-Number: 40
>
>i have a small chunk of code which i was wondering why it wasn't working.  i
>have the projects debugging level 1 up from "no optimizations".  when i
>place some frmCustomAlerts, a calculation is made, and some numbers are
>assigned to ulongs.  but when i remove the customAlerts, it totally skips
>the calculation which is importent.  so i tried putting the optimizations to
>none and see what it does and now it does it.  can anyone bring up anything
>that might cause this bug?  i say bug, because an optimizer isn't supposed
>to skip lines of code.
>
>
>Word CheckXORAdjustData(ULong serverDate, UShort offSet) {
>  ULong curDate;
>  ULong offSetSec;
>  ULong dateDiff;
>
>  curDate=TimGetSeconds(); // get units time in seconds
>  if(curDate==serverDate) { // if seconds match then exit
>   return 0;
>  }
>  offSetSec=offSet*60;  // get offset in seconds
>
>  if(curDate>serverDate) {
>//  FrmCustomAlert(TestAlert, "TEST", " ", " ");        // <---- these two
>lines if removed make the entire if statement skipped
>   dateDiff=curDate-serverDate;
>  } else {
>//  FrmCustomAlert(TestAlert, "TEST2", " ", " ");        // <---- these two
>lines if removed make the entire if statement skipped
>   dateDiff=serverDate-curDate;
>  }
>
>  if(dateDiff>offSetSec) {
>   TimSetSeconds(serverDate);
>   return 2;
>  }
>
>  return 1;
>}

Ken Krugler
TransPac Software, Inc.
<http://www.transpac.com>
+1 530-470-9200

-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/tech/support/forums/

Reply via email to