This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CCS/MSP430FR5969: Variable is not created during debug

Part Number: MSP430FR5969


Tool/software: Code Composer Studio

Hi all,

I'm working on extracting a real number out of a string (an array of characters). I wrote a function to do this, and during debug I realized that a variable of float (to hold the extracted real number) was not created as I expected it to. Can anyone help me to fix it. Thank you!

P/s: the tem variable was also not created until I initialized it with "long tem = 0;"

float realnum_extractor(char array[], unsigned int i){
	unsigned int j, k;
	long tem = 0;
	float real1 = 0;
	for(j = i; array[j] != '.'; j++);						//to get no. of digits to the left of "."
	for(k = i; array[k] != ','; k++);						//to get no. of digits
	k--;													//"." does not count
	for(i; i < j; i++){
		tem += (array[i]-48)*pow(10,k-i-1);
	}
	for(i = j + 1; i <= k; i++){
		tem += (array[i]-48)*pow(10,k-i);
	}
	real1 = (float) tem/pow(10,k-j);
	return real1;
}

  • By default, the compiler optimizes your code at level 0, as if you specified --opt_level=0.  This optimization causes the variable real1 to disappear.  This ..

    Nhan Tran said:
    real1 = (float) tem/pow(10,k-j);
    return real1;

    ... changes to ...

        return (float) tem/pow(10,k-j);

    If you disable all optimization with --opt_level=off, then you will see real1 in CCS.

    Thanks and regards,

    -George

  • Thank you George!
    I turned off the optimization of CCS and my code works correctly. But I'm still a bit confused. The idea of the optimized code is the same (real1 = (float) tem/pow(10,k-j); return real1; changes to return (float) tem/pow(10,k-j);) but the "optimized" stuff does not work. It yields strange looking results while my original code would work just fine. Somehow CCS messed it up :))) Again, I appreciate your help.
  • With regard to the final result returned from the function, you should get the same result no matter what --opt_level is used.  I need to somehow reproduce the problem.

    What version of the compiler (not CCS) do you use?  Please show the build options exactly as the compiler sees them.  Please show function input (a string for array[] and a value for i) that causes an incorrect result to be returned.

    Thanks!

    -George

  • While we would definitely like to see a test case demonstrating the potential bug you've found, I would suggest you might want to change the function so that it calls the standard function strtod.