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

Changing global var on a function that doesn't use it !!!

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



Joined: 09 Apr 2009
Posts: 29

View user's profile Send private message

Changing global var on a function that doesn't use it !!!
PostPosted: Wed Nov 10, 2010 3:17 am     Reply with quote

Hi friends
I have a program that has one global var (unsigned int16) and I'm using 18F452.
I use this variable in main and timer1_int. I have some function too. When I call one function it does its work fine but changes my global variable too!!! (I never use this variable on that function).
I mean before calling that function my global variable is ok in main but after come back from the function it changes (I don't use global var on that function).
I have looked at asm program in lst file too. I didn't see any work on global var by that function but it changes!!
What's the problem?
Regards
_________________
Sorry if i have much mistakes, my english is not good.
Thanks a lot for your helps.
Have a good time
vinniewryan



Joined: 29 Jul 2009
Posts: 154
Location: at work

View user's profile Send private message MSN Messenger

PostPosted: Wed Nov 10, 2010 4:23 am     Reply with quote

Please post the code and your compiler version.

Try writing a test code and comment out certain lines of code in the 'function in question' to narrow down exactly what function or line of code is changing your global variable.

I can't say much more without seeing the code.
_________________
Vinnie Ryan
Ttelmah



Joined: 11 Mar 2010
Posts: 19328

View user's profile Send private message

PostPosted: Wed Nov 10, 2010 4:30 am     Reply with quote

Most likely, something going beyond the area it is meant to.

Do you use any arrays, or pointer in the function?.
The 'classic' problem is (for example), having an array of eight characters, and writing an 8 character string to this. Forgetting that a 'string', always has an extra character for the terminator. This then results in the next variable in memory getting corrupted....

So, open the .sym file. This shows 'where' variables are stored in memory. Find where the global variable is stored. Then look at what is stored immediately in front of this. Is this a variable in the problem function?. Then look at how this is declared, and used. The variables immediately in front, are the 'most likely' to cause a problem.
Beyond this, are you using pointers anywhere in the function?. If so, triple check that declarations are correct for these, and indexes are correct. Then the same for arrays. Another 'classic', is forgetting that in C, arrays are 'zero referenced', so if you create an array of twenty elements, you can use a[0] to a[19]. If you accidentally use a[20], this results in the next variable getting corrupted....

Best Wishes
Study



Joined: 09 Apr 2009
Posts: 29

View user's profile Send private message

PostPosted: Wed Nov 10, 2010 5:25 am     Reply with quote

Thanks a lot Ttelmah
I think the problem is what you say, I have global array too that i use it on function, it stors at: 019-01C and my global var is on 01D-01E.
what should i do now?
_________________
Sorry if i have much mistakes, my english is not good.
Thanks a lot for your helps.
Have a good time
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

PostPosted: Wed Nov 10, 2010 6:36 am     Reply with quote

Check your counter (index) for traversing the Array.

Its probably going out of bounds.

Most likely in the function that over writes your variable contains a loop.

Check its limits.


I think I just said the same thing twice.
_________________
CCS PCM 5.078 & CCS PCH 5.093
Study



Joined: 09 Apr 2009
Posts: 29

View user's profile Send private message

PostPosted: Wed Nov 10, 2010 9:28 am     Reply with quote

I got answer, Thanks a lot for your helps friends Smile
_________________
Sorry if i have much mistakes, my english is not good.
Thanks a lot for your helps.
Have a good time
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