ROBOTC.net forums
http://robotc.net/forums/

Improper logical expression evauation
http://robotc.net/forums/viewtopic.php?f=1&t=331
Page 1 of 1

Author:  Olorin [ Tue Jan 01, 2008 2:43 pm ]
Post subject:  Improper logical expression evauation

When using the debugger, the if statement in the aTask thread does not evaluate properly; i.e., when time_msec is negative, the expression still evaluates as true, and the debugger steps to the wait1Msec. Note: the following was intentionally modified to provide a negative value of time_msec.

Code:
task aThread()
{
  short time_msec = 0;

  while(true)
  {
    // Start timer
    time1[T1] = 0;
    time_msec = time1[T1];
    wait1Msec(50);
    time_msec -= time1[T1];
    nxtDisplayTextLine(2,"%d msec",time_msec);
// !!! the following line does not evaluate as false when using the debugger with time_msec < 0 !!!
    if(time_msec > 0)
    {
      // Put this task to sleep for the remainder of the sample time
      wait1Msec(time_msec);
    }
  }
}

task main()
{
  StartTask(aThread);
  // Display sensor data untill this task is externally killed
  while(true)
  {
    wait1Msec(100);
  }

  StopAllTasks();
}


- Olorin

Author:  Olorin [ Tue Jan 01, 2008 4:15 pm ]
Post subject:  Improper logical expression evauation

Apparently, this is only a problem with the debugger break points (pausing execution) in "threads".

I have no problem using the debugger with a similar situation within the scope of main.

I replaced the use of breakpoints in the above source with an additional variable counter that indexed each time the expression failed to evaluate properly. Without stopping execution, I watched the counter in the debug window, and it did not increment (the expression evaluated properly).

I hope these clues may help the development team.

Cheers,
Olorin

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/