View previous topic :: View next topic |
Author |
Message |
monkeyman
Joined: 05 Jun 2008 Posts: 18
|
variable never used?! strange problem!! |
Posted: Tue Sep 09, 2008 3:23 am |
|
|
Hello
I have a strange problem with a variable in my main:
float temp_flo;
This variable is never used, the compiler say that to me and the program work fine.
When i delete this variable, my program stop to work!?
My version of compiler is PCWH 4.078.
Is anybody understanding...
thanks! |
|
|
RLScott
Joined: 10 Jul 2007 Posts: 465
|
Re: variable never used?! strange problem!! |
Posted: Tue Sep 09, 2008 5:57 am |
|
|
No, you have not given enough information for anyone to help you. You didn't even say how your program fails.
But as an experiment, try adding another variable that is also not used anywhere but takes up the same amount of memory, like an int32, and see if that helps. That would show that the problem has something to do with memory allocation. _________________ Robert Scott
Real-Time Specialties
Embedded Systems Consulting |
|
|
Indy31 Guest
|
|
Posted: Tue Sep 09, 2008 7:29 am |
|
|
Most likely you are corrupting memory.
For example the following program: Code: | int8 Array[10];
int8 Foo;
for (i=0; i<=10; i++)
Array[i] = 0; | This contains a very common bug where we are writing outside the array bounds at element Array[10] (arrays start counting at number 0, not at 1). It is very likely from the program flow that variable Foo is mapped directly in the memory after variable Array. Overwriting Foo will go unnoticed because it is never used.
Check the symbol file (*.sym) to see which variable is in memory directly in front of your not used variable. Most likely that is the variable that is causing your memory corruption.
It is possible you have to enable the generation of the symbol file in your project settings first. |
|
|
monkeyman
Joined: 05 Jun 2008 Posts: 18
|
|
Posted: Wed Sep 10, 2008 9:17 am |
|
|
thank you Indy
your example is so good
in my old main :
char CH1[20];
char CH2[1];
float temp_flo;
disable_interrupts(global);
setup_wdt (WDT_ON);
...
I have saw the *.sym and now i know it, thank you.
I have replace char CH2[1];(so bad) by char CH2[2]; and it work fine.
thanks a lot |
|
|
|