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 CCS Technical Support

static variables and multiple .c files

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







static variables and multiple .c files
PostPosted: Tue Sep 20, 2005 6:01 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Sep 20, 2005 6:17 pm     Reply with quote

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







PostPosted: Wed Sep 21, 2005 12:53 am     Reply with quote

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

View user's profile Send private message Send e-mail

PostPosted: Wed Sep 21, 2005 6:47 am     Reply with quote

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;
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