This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

variables values changes unexpectly

I declare these variables:

unsigned long idata xpaquetes,xbytes;
unsigned long errors,PHY,CRC;

I ran my progran and after 3 minutes the errors,PHY and CRC variables change to
0xaaaaaaaaaaaaaaaa

but the xpaquetes and xbytes still have the right value?

I think something is wrong during compilation
because my program started counting and updating these variables but after few minutes these variables are unstable

what can I do?

I put now :

unsigned long xdata errors,PHY,CRC;

but I got the same error

please give me suggestions

Parents
  • I have a similar problem.
    The following is code snippet:

    	a = Float2Int(23.1);
    	a = Float2Int(23.5);
    	a = Float2Int(-23.6);
    	a = Float2Int(-23.1);
     	a = ceil(-23.6);
    	a	 = (int) UcharAverage(ucA,10);
    	//after the sentence the a's value will be uncetain
    	iAvg = IntAverage(iA,10);
    	fAvg = FloatAverage(fA,10);
    
    	Float2asc(-1278.98791,ucA);
    	Float2asc(-99999.89971,ucA);
    
    after the sentece a = (int)UcharAverage(ucA,10);
    the value of a is changed irregularly.Note that,the a's value is never used later.
    However when I add a sentence behind,
    ...
    	a	 = (int) UcharAverage(ucA,10);
    	iAvg = IntAverage(iA,10);
    	fAvg = FloatAverage(fA,10);
          b = a;
    	Float2asc(-1278.98791,ucA);
    ...
    
    then the value of a is never changed. I think the reason is that,the variable(a) is not referenced any more later,so the compiler judge the space for the variable is unusful and frees the memory space.It depends on the compiler's optimization.But when it used later,the compiler think the variable may be used later on again,so it never freed the memory space.

Reply
  • I have a similar problem.
    The following is code snippet:

    	a = Float2Int(23.1);
    	a = Float2Int(23.5);
    	a = Float2Int(-23.6);
    	a = Float2Int(-23.1);
     	a = ceil(-23.6);
    	a	 = (int) UcharAverage(ucA,10);
    	//after the sentence the a's value will be uncetain
    	iAvg = IntAverage(iA,10);
    	fAvg = FloatAverage(fA,10);
    
    	Float2asc(-1278.98791,ucA);
    	Float2asc(-99999.89971,ucA);
    
    after the sentece a = (int)UcharAverage(ucA,10);
    the value of a is changed irregularly.Note that,the a's value is never used later.
    However when I add a sentence behind,
    ...
    	a	 = (int) UcharAverage(ucA,10);
    	iAvg = IntAverage(iA,10);
    	fAvg = FloatAverage(fA,10);
          b = a;
    	Float2asc(-1278.98791,ucA);
    ...
    
    then the value of a is never changed. I think the reason is that,the variable(a) is not referenced any more later,so the compiler judge the space for the variable is unusful and frees the memory space.It depends on the compiler's optimization.But when it used later,the compiler think the variable may be used later on again,so it never freed the memory space.

Children
No data