Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C > Sharing a varia...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 3 Topic 25416 of 27343
Post > Topic >>

Sharing a variable across multiple files

by aruna.mysore@[EMAIL PROTECTED] Apr 7, 2008 at 12:11 PM

Hi all,

I have specific question about usage of extern. I want to share a
single variable say int a; across multiple files.

I would define it in file1.c as

int a=0;
int main()
{
    .........
   a= 20;
  ..........
}

In another file2.c I would use it as,

int main()
{
  extern int a;
  ................
  printf("value of a=%d\n", a);

  ..................
}

Is this usage right. If yes, how do I run these as two separate
processes so that value changed in file1 is always reflected in file2
whenever it is used in fil2.c. How do I link these two processes put
it in another way.

Regards,
Aruna
 




 3 Posts in Topic:
Sharing a variable across multiple files
aruna.mysore@[EMAIL PROTE  2008-04-07 12:11:54 
Re: Sharing a variable across multiple files
Morris Dovey <mrdovey@  2008-04-07 14:19:58 
Re: Sharing a variable across multiple files
Antoninus Twink <nospa  2008-04-07 22:17:43 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Sep 6 21:55:42 CDT 2008.