View previous topic :: View next topic |
Author |
Message |
Simon Guest
|
static variables and multiple .c files |
Posted: Tue Sep 20, 2005 6:01 pm |
|
|
Hi,
I have been searching through the forums and I am aware that you cannot link multiple .c files, you have to #include them.
What I am wondering is how this affects the ability to use the static key word. I would like to create device drivers and some state machines which would be split into multiple .c files, and there is the possibility that I need "file specific static globals". I don't want them to be referenced outside of the device driver, and I don't want to have to trawl through my libraries to ensure that I haven't used a duplicate variable name...
Can I achieve this? I figure I can't but thought I would ask.
Thanks,
Simon |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Sep 20, 2005 6:17 pm |
|
|
Quote: | I don't want to have to trawl through my libraries to ensure that
I haven't used a duplicate variable name... |
Because it's essentially one big file, you don't have to worry about
having duplicate variable names by mistake. Any duplicate names will
be flagged with as an error when you compile the code. ie:
"Identifier is already used in this scope" |
|
|
Simon Guest
|
|
Posted: Wed Sep 21, 2005 12:53 am |
|
|
Thanks, I figured as much... still a very unsatisfactory way of doing things because when someone else uses the code they have access to variables they are not supposed to be using... |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Wed Sep 21, 2005 6:47 am |
|
|
Simon wrote: | Thanks, I figured as much... still a very unsatisfactory way of doing things because when someone else uses the code they have access to variables they are not supposed to be using... |
Limit the use of globals. If you must use one, then you can reserve a memory location and access the variable as though it were a pointer
Code: |
#reserve 0x40
#define myvar *0x40
myvar = 20;
|
|
|
|
|