Restricting the access of a Global variable

Discussion in 'C Programming' started by sant.tarun@gmail.com, Jan 17, 2008.

  1. Guest

    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
     
    , Jan 17, 2008
    #1
    1. Advertising

  2. <> 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
     
    Malcolm McLean, Jan 17, 2008
    #2
    1. Advertising

  3. Mark Bluemel Guest

    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)?
     
    Mark Bluemel, Jan 17, 2008
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andrew Banks

    Restricting access based on roles

    Andrew Banks, Feb 26, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    277
    Andrew Banks
    Feb 26, 2004
  2. =?Utf-8?B?SnVzdGlu?=

    Restricting access to certain pages

    =?Utf-8?B?SnVzdGlu?=, Oct 31, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    343
    Chris Austin
    Oct 31, 2004
  3. Graham Matthews

    restricting package access in loaded code

    Graham Matthews, Jan 16, 2004, in forum: Java
    Replies:
    2
    Views:
    330
  4. Replies:
    1
    Views:
    442
    Gordon Beaton
    Dec 21, 2004
  5. knightowl

    Restricting Class Access

    knightowl, Mar 6, 2005, in forum: Java
    Replies:
    3
    Views:
    332
    knightowl
    Mar 6, 2005
Loading...

Share This Page