Access variable using extern in a paricular file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nnk1220
    New Member
    • Sep 2013
    • 3

    Access variable using extern in a paricular file

    Hi ALL,

    My question is :

    I have 3 files: f1.c f2.c and f3.c

    I have declared variable int a; in f1.c and int a; in f2.c.

    Now I want to use the variable int a; in f3.c . But this variable corresponds to the variable in f2.c . How to do this ????

    Thanks
  • anonuser
    New Member
    • Aug 2013
    • 6

    #2
    in short, don't. do you have some particular problem you're trying to solve?

    Comment

    • nnk1220
      New Member
      • Sep 2013
      • 3

      #3
      @ anonuser :

      Yes, there is a problem. When I try to access the variable in f3.c, the compiler picks the value of variable from any of the two files f1.c or f2.c.

      Comment

      • weaknessforcats
        Recognized Expert Expert
        • Mar 2007
        • 9214

        #4
        Read this: http://bytes.com/topic/c/insights/73...obal-variables

        Comment

        • anonuser
          New Member
          • Aug 2013
          • 6

          #5
          i realize that - my question is, why are you trying to have multiple copies of the variable by the same name? in general, it is bad practice to have variables outside function/class scope by DIFF names, let alone the same name. the linker can't distinguish between them.

          what is the underlying reason you're doing this, please?

          Comment

          Working...