CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

variable never used?! strange problem!!

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
monkeyman



Joined: 05 Jun 2008
Posts: 18

View user's profile Send private message

variable never used?! strange problem!!
PostPosted: Tue Sep 09, 2008 3:23 am     Reply with quote

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!? Twisted Evil

My version of compiler is PCWH 4.078.

Is anybody understanding...

thanks!
RLScott



Joined: 10 Jul 2007
Posts: 465

View user's profile Send private message

Re: variable never used?! strange problem!!
PostPosted: Tue Sep 09, 2008 5:57 am     Reply with quote

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







PostPosted: Tue Sep 09, 2008 7:29 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Sep 10, 2008 9:17 am     Reply with quote

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 Wink
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group