Tool/software: Code Composer Studio
Hi
CCS 3.3.82.13
Compiler 4.1.3
For below local variable all and half.
1. The value in debugging environment is right only if we add volatile in front of variable or none optimize.
int64 half2quan(int32 target,int64 now, Uint16 Axis)
{
volatile
int64 all,half;
int64 TMP;
// long lsd;
// lsd=0x80000000;
// min=(int64)lsd*Position_Numerator1/Position_Divisor1;
// lsd=0x7fffffff;
// max=(long long)lsd*Position_Numerator1/Position_Divisor1;
// half=(int64)0x80000000;
// half=(int64)half*Position_Numerator1/Position_Divisor1;
all=(int64)0x100000000;
all=(int64)all*Position_Numerator1/Position_Divisor1;
half=all;
half=half>>1;//((int64)all>>1);
TMP = (int64)target*Position_Numerator1/Position_Divisor1-now;
if(TMP>half) TMP-=all;
else if(TMP<-half) TMP+=all;
return TMP;
}
2. if set optimize level to 3 or remove volatile. The value is wrong.
Could you let me know does it caused by old compiler ? Why should we must add volatile for a local variable? Thanks.