View previous topic :: View next topic |
Author |
Message |
deepakomanna
Joined: 06 Mar 2007 Posts: 92 Location: Pune,India
|
need some help about static variables |
Posted: Wed Sep 05, 2007 12:25 am |
|
|
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
|
|
Posted: Wed Sep 05, 2007 12:50 am |
|
|
This sounds like a homework or a quiz question. |
|
|
anestho
Joined: 27 Dec 2006 Posts: 28
|
|
Posted: Wed Sep 05, 2007 5:11 am |
|
|
What is the actual question here???? Why not try it and see? ;) |
|
|
icesynth
Joined: 03 Sep 2007 Posts: 32 Location: Edmonton, Alberta
|
|
Posted: Wed Sep 05, 2007 8:32 am |
|
|
Yep, sounds like homework
Yes, the value of inc_min will be 0 or 40, dec_number will be 255 or 90
At what point in the code are you looking at the variables after you start the micro again
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
|
|
Posted: Wed Sep 05, 2007 1:54 pm |
|
|
'static' is really redundant for globals (they behave as static anyway), much like 'auto' is for variables inside functions
What static *does not* mean is non-volatile (at least in standard C) |
|
|
|