Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Restricting the access of a Global variable

Reply
Thread Tools

Restricting the access of a Global variable

 
 
sant.tarun@gmail.com
Guest
Posts: n/a
 
      01-17-2008
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

 
Reply With Quote
 
 
 
 
Malcolm McLean
Guest
Posts: n/a
 
      01-17-2008

<(E-Mail Removed)> wrote in message > 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'.
>

/*
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

 
Reply With Quote
 
 
 
 
Mark Bluemel
Guest
Posts: n/a
 
      01-17-2008
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> 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)?
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Initialize global variable before any other global variables jubelbrus C++ 5 07-20-2007 06:38 PM
FWSM/PIX and Dynamic PAT using global IP range vs. global interface vs. global IP Hoffa Cisco 1 10-25-2006 06:50 PM
FWSM/PIX and Dynamic PAT using global IP range vs. global interface vs. global IP Hoffa Cisco 0 10-25-2006 01:04 PM
Is mymodule.myvariable a 'global'? (What is proper definition of 'global variable'?) seberino@spawar.navy.mil Python 1 08-21-2005 09:21 PM
Use Global Variable or Global Struct??? Bryan Parkoff C++ 2 11-27-2004 02:46 AM



Advertisments