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

How to declare persistent global variable?

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



Joined: 14 Dec 2007
Posts: 257

View user's profile Send private message Send e-mail

How to declare persistent global variable?
PostPosted: Tue Jun 16, 2009 2:35 pm     Reply with quote

Hello,

I am trying to declare a persistent global variable and the compiler is giving me errors.

Right before main() I write:

Code:

persistent int cal_cancelled_flag;


And the compiler is giving me an error:
*** Error 48 "Line 38(12,22): Expecting a (
*** Error 48 " Line 38(16,34): Expecting a (

Now if I remove the persistent label the code is fine.

I am using PCH 4.064 compiler with 18f2525.
ak6dn



Joined: 08 Jan 2006
Posts: 23
Location: Saratoga, CA USA

View user's profile Send private message

Re: How to declare persistent global variable?
PostPosted: Tue Jun 16, 2009 2:48 pm     Reply with quote

mkuang wrote:
Now if I remove the persistent label the code is fine.


That is a clue. 'persistent' is not a language keyword that CCS C defines. Have you read their manual?

If you want persistent storage, you need to manage it manually in a device that has EEPROM data storage.
_________________
Give a man a fish and you'll feed him for a day. Teach a man to fish, and you'll never see him on the weekend.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jun 16, 2009 2:50 pm     Reply with quote

That's not an keyword in CCS C. Of course it will give an error.
See the manual for keywords:
http://www.ccsinfo.com/downloads/ccs_c_manual.pdf

Look at the 'static' keyword.
Ttelmah
Guest







PostPosted: Tue Jun 16, 2009 2:59 pm     Reply with quote

In C, the traditional persistent variable, is declared with the 'static' keyword. Persistent, is not a normal C keyword.
The difference between 'persistent', and 'global', in the normal meaning of the term is that a persistent variable is local in scope.

Some 'third party' languages, use the 'global persistent' keyword in C, for a variable that is maintained after power is removed. this does not exist in CCS, mainly because the only memory that can be used for this, is the EEPROM, which suffers from severe timing overhead, when written, and limited write life, making it unsuitable for 'variables'.

If you want to make a variable behave as 'global persistent', then _you_ need to read it from EEPROM on boot, and write it (preferably _infrequently_), when changed.

Best Wishes
mkuang



Joined: 14 Dec 2007
Posts: 257

View user's profile Send private message Send e-mail

PostPosted: Tue Jun 16, 2009 3:08 pm     Reply with quote

Thanks guys for all your help.
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