|
On Tue, 16 May 2000, Tobias Bende wrote:
> I read that legOS only declared varibles the first time the program is run.
> Does this mean I cannot use local variables. I have loops in different
> functions using 'i' as looping variable, which is locally declared. Should I
> avoid this?
I think you're confusing the issue a little bit. LegOS only initializes
GLOBAL variables when the program is loaded. So, for example, a global
variable declared like:
int foo = 4;
Will only be initialized to 4 when the program is loaded. If you increment
foo in your main function and don't reset it, foo will be 5 the next time
you run the program. This also applies to static local variables in
functions. Normal local variables are always taken care of properly each
time the function is called, though. (If I'm mistaken here, please tell
me! My programs would thank you! :)
--
"Our doubts are traitors, and make us lose the good we oft might win by
fearing to attempt." - William Shakespeare
Mike Ash - <http://www.mikeash.com/>, <mailto:mail@mikeash.com>
|
|
Message has 1 Reply: | | Re: local variables
|
| (...) This is completely true and is basically a feature of the C language. Globals aren't technically "initialized" at all. They are just loaded as part of the image. You could consider that they are initialized at compile time. On a workstation OS (...) (25 years ago, 17-May-00, to lugnet.robotics.rcx.legos)
|
Message is in Reply To:
| | local variables
|
| Hi! I read that legOS only declared varibles the first time the program is run. Does this mean I cannot use local variables. I have loops in different functions using 'i' as looping variable, which is locally declared. Should I avoid this? Tobias (25 years ago, 16-May-00, to lugnet.robotics.rcx.legos)
|
3 Messages in This Thread:
- Entire Thread on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
This Message and its Replies on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
|
|
|
|