Forum : 8051
Original Post
Post Information | Post |
---|---|
May 19, 2008 - 5:13pm
|
Hi, I need some static variables in my function but declaring variables like: static unsigned char myVar=15; when evaluated it appears to be 0. What am I missing? Thx Henk |
static variables are supposed to be initialized by the startup routine. Are you using the default startup or your own?
Hi,
>Are you using the default startup or your own?
I allready included the file 'startup.a51' in my project if that's what you mean.
If I use the Option:
Option > Project > RC51 > Code generation > Initialize static variables to 0
does this mean that initialized static variables are set to zero?
Henk
At a first step, I suggest that you select the default startup:
Options > Project > LX51 > Startup > Default Startup
It should work (or it means that there is a bug in the compiler).
Then (if it works), you should analyze why your startup does initialize the static/global variables.
In the original startup, it is done in the area marked by:
IF INIDATA <> 0
but there are several parameters that have to be set.
Hi,
>Options > Project > LX51 > Startup > Default Startup
was allready set this way.
If I want a (global) xdata variable to be accessible throughout different modules do I have to declare it like:
static xdata unsigned char myVal; //in module A
extern xdata unsigned char myVal; //in module B
or
xdata unsigned char myVal; //in module A
extern xdata unsigned char myVal; //in module B
???
I searched Internet and read all Raisonance pdf manuals but I didn't succeed in finding the answer.
Thx,
Henk
That's a general 'C' question. If you specify 'static' for a global variable in module A, it will NOT be visible in other modules (it would be considered as a 'private' variable in a C++ class).
Note that for a local variable, 'static' has a different meaning since it changes the allocation type (for a local variable, 'static' means 'non-automatic'.
Look here: http://c-faq.com/
As it's a standard 'C' question - nothing specifically to do with Raisonance or the 8051 - it should also be covered in any decent 'C' textbook.