variable 'not allocated'?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

variable 'not allocated'?

1,937 Views
urlreader
Contributor I
I'm using code warrior to debug a firmware for a QG8 device. However, in the debug mode, most local variables are shown as 'not allocated'. And it seems the firmware doesn't work correctly too.

I changed the stacksize in project.prm to 0xB0, but still have the problem. I guess it is the memory problem. So, I commented most part of the firmware, but the problem still exists.

What can cause this? How to solve it?


thanks

Tan
Labels (1)
0 Kudos
3 Replies

389 Views
shrine
Contributor I
I wonder did you really change the value of the local variables in the 'local scope'?

I mean if you did not change the value of the local variables or changed them  somewhere outside the 'local scope', for instance, within a ISR, that could occur depends on your compiler and optimization level. Some compilers might consider the 'unchanged' variable is no use at all and remove them from the target code for optimization.

So,  qualify them as 'volatile' to prevent  that, especially when you deal with variables changed in ISR. The following is an example from CW's help.

volatile int x;
void main(void) {
  x = 0;
  ...
  if (x == 0) { // without volatile attribute, the
                // comparison may be optimized away!
    Error();    // Error() is called without compare!
  }
}

0 Kudos

389 Views
airbusboy20
Contributor I
Declaring the variable as "volatile" generally solves this problem for me.
 
Just remember to remove "volatile" when you've finished debugging if it's not actually required...


Message Edited by airbusboy20 on 2007-08-28 09:00 AM
0 Kudos

389 Views
CrasyCat
Specialist III
Hello
 
I cannot tell you why your firmware is not working, but I can explain when the debugger specifies local variable are not allocated.
 
The debugger might notify that when local variables values are not stored on the stack, but kept in registers.
 
Also a local variable have a specific scope. They are valid only for the portion of the function where they are used. 
A local variable might not be available any more after the last instruction using it in the function.
 
CrasyCat
0 Kudos