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

need some help about static variables

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



Joined: 06 Mar 2007
Posts: 92
Location: Pune,India

View user's profile Send private message AIM Address Yahoo Messenger

need some help about static variables
PostPosted: Wed Sep 05, 2007 12:25 am     Reply with quote

Dear sir,
In my programe i globally declare two static variables,
Code:
static int8 inc_min = 0;
static int8 dec_number = 255;
 
void main()
{

====some statements====

fun();

}

void fun()
{
inc_min++;
   // consider here current incremented inc_min is 40.
dec_number --;
   // consider here current decremented dec_number is 90.
}

at this position if i switch off my controller & again switch ON,
then value of inc_min will be 0 or 40, & dec_number will be 255 or 90.
_________________
Thank You,
With Best Regards,
Deepak.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Sep 05, 2007 12:50 am     Reply with quote

This sounds like a homework or a quiz question.
anestho



Joined: 27 Dec 2006
Posts: 28

View user's profile Send private message

PostPosted: Wed Sep 05, 2007 5:11 am     Reply with quote

What is the actual question here???? Why not try it and see? ;)
icesynth



Joined: 03 Sep 2007
Posts: 32
Location: Edmonton, Alberta

View user's profile Send private message Visit poster's website

PostPosted: Wed Sep 05, 2007 8:32 am     Reply with quote

Yep, sounds like homework Laughing

Yes, the value of inc_min will be 0 or 40, dec_number will be 255 or 90
Twisted Evil

At what point in the code are you looking at the variables after you start the micro again Question

Remember, the RAM is in an undefined state on a micro when it is powered down then back up again. It is up to the user to actually reset the values on startup or save them into EE before power down so that they may be retrieved later.
_________________
Programming for the the real world.
--Chris Burchett
Sylver Technologies Inc.
SET



Joined: 15 Nov 2005
Posts: 161
Location: Glasgow, UK

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Wed Sep 05, 2007 1:54 pm     Reply with quote

'static' is really redundant for globals (they behave as static anyway), much like 'auto' is for variables inside functions Wink

What static *does not* mean is non-volatile (at least in standard C)
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