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 CCS Technical Support

Scratch and main variable corruption

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



Joined: 11 Mar 2010
Posts: 19536

View user's profile Send private message

Scratch and main variable corruption
PostPosted: Tue Nov 12, 2013 1:24 am     Reply with quote

This harks back to an old thread:

<http://www.ccsinfo.com/forum/viewtopic.php?t=51298&highlight=atan2>

In this, Jeremiah refers to having had a similar problem with the maths, overwriting a scratch variable. I'm experiencing something worse. V5.01x.

Basically using some fairly 'aggressive' arithmetic (atan2, exp, and log10), with quite a few normal calculations as well. What I'm seeing is the compiler overwriting variables declared in the main code. So:

Code:

2E4-2E9 MAIN.adc_sums
2E6-2E9 atan2.z
2EA     MAIN.state
2EA.0   atan2.sign
2EB     MAIN.amreading
2EB     atan2.quad

So the 'adc_sums', 'state', and 'amreading' values get overwritten when the maths is used. Result 'garbage'.

Now the maths is all performed in the main (so should respect variables declared here), yet this happens.
If I declare the variables as static, it all works fine.
The same code compiled with a much older compiler (4.118), works OK, and doesn't overwrite the variables.
It seems to be doing this with all the V5 releases I have tried. .008, 010, 012, 013 etc..
It never seems to overwrite 'simple' variables. adc_sums is an array, and state, and amreading are both enums.

Now I have a workround, by using 'static', but my problem is generating some simpler code that displays the problem, so I can show it to CCS. I can't send them the core part of the code that shows the problem, since the algorithm here is 'commercial', and bound by some fairly strict constraints.

So has anyone else had problems with complicated bits of arithmetic giving unexpected results, or other variables changing with a V5 compiler, with code that is small enough to share, and is not bound by commercial agreements?.
I've been playing for quite a few hours trying to generate some shareable code that displays the fault, but thought I'd ask if anyone else was having the problem?. You might not even realise this was 'why' you were getting silly results....

It is giving problems on both PIC18's, and PIC24's with the original code (suitably modified).

Best Wishes
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Tue Nov 12, 2013 9:56 am     Reply with quote

thanks for the heads up!

for now, i'm planning to declare all vars as static or global unless i run out of
mem space, and then back into only using temps in functions to make the program compile.

may i assume that option is not open to you ?
Ttelmah



Joined: 11 Mar 2010
Posts: 19536

View user's profile Send private message

PostPosted: Wed Nov 13, 2013 12:10 am     Reply with quote

No, globals are working fine.
In the main there is no loss of space. On the compilers that work, the code puts the temp variables for atan in the same area as those for exp, which since they can't be called inside each other, is no problem. On the ones with problems the atan variables get put over main variables.

I want to show CCS the problem....

Best Wishes
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