Connecting Tech Pros Worldwide Help | Site Map

Restricting the access of a Global variable

sant.tarun@gmail.com
Guest
 
Posts: n/a
#1: Jan 17 '08
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

Malcolm McLean
Guest
 
Posts: n/a
#2: Jan 17 '08

re: Restricting the access of a Global variable



<sant.tarun@gmail.comwrote in message Hi,
Quote:
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.

--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm

Mark Bluemel
Guest
 
Posts: n/a
#3: Jan 17 '08

re: Restricting the access of a Global variable


sant.tarun@gmail.com wrote:
Quote:
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)?
Closed Thread