Curt Stienstra

Error in Optimized Code (pre-increment)

Discussion created by Curt Stienstra on Feb 5, 2007
Latest reply on Feb 7, 2007 by CrasyCat
I was debugging a problem and noticed some unexpected output with the following code:

void SomeFunct(void)
{
char buffer[100];
int j;

j = 0;

Foo( buffer[++j], j );
}

void Foo(char *buffer, int index)
{

}

With optimization at level 4, index in Foo(...) would be passed in as 0, with optimization off (level 0) index would be 1. I just moved the increment out of the call to Foo(…) to get things working but wanted to report this problem (especially since the source code that exposed the problem was from a Freescale seminar.)

I’m using CodeWarrior Development Studio for ColdFire Architectures Version 6.3 (Preview Release) and targeting the MCF52233 Coldfire.

Outcomes