Restricting the access of a Global variable

S

sant.tarun

Hi,
I am facing some some problem in restricting the access of a
variable....
My question is described below.....

Let I have two different C source files 'a.c' and 'b.c'.

In the file 'a.c' there is a global variable declared 'int
GlobalVariable' and the same variable is extern in the file 'b.c'.

a.c b.c
----------------------- ---------------------------
|int Globalvariable; | |extern int Globalvariable;
|int main() | |
|{ | |Other funtions
|...... | |{
|} | |......
| | |}
|---------------------- ----------------------------

Now I want to restrict the access of that variable "Globalvariable" in
the file 'b.c' without using any semaphore.

Thanks and Regards,
Tarun Sant
 
M

Malcolm McLean

I am facing some some problem in restricting the access of a
variable....
My question is described below.....

Let I have two different C source files 'a.c' and 'b.c'.

In the file 'a.c' there is a global variable declared 'int
GlobalVariable' and the same variable is extern in the file 'b.c'.
/*
b.c
*/
static int globalVar = 2;

/*
a.c
*/
int globalVar = 3;

/*
a.h
*/
extern int globalVar;

Now anything that includes a.h can access its version of gloablVar, whilst
the version in b.c is safely locked away.
 
M

Mark Bluemel

Hi,
I am facing some some problem in restricting the access of a
variable....
My question is described below.....

Let I have two different C source files 'a.c' and 'b.c'.

In the file 'a.c' there is a global variable declared 'int
GlobalVariable' and the same variable is extern in the file 'b.c'.

a.c b.c
----------------------- ---------------------------
|int Globalvariable; | |extern int Globalvariable;
|int main() | |
|{ | |Other funtions
|...... | |{
|} | |......
| | |}
|---------------------- ----------------------------

Now I want to restrict the access of that variable "Globalvariable" in
the file 'b.c' without using any semaphore.

What do you mean by "restrict the access"? Be more precise and we may be
able to help.

As you are talking about semaphores, are you implying you want to
enforce some form of serialization of access (perhaps by multiple
threads)?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top