Global and Static

H

hyderabadblues

I have a doubt regarding how to access global variables if already
there is one static variable with the same name defined at the
beginning of file outside any function.

E.g:
//File client.c
int iGlobalVar; // Global Variable

// main.c

static int iGlobalVar;

int main()
{
// How to access iGlobalVar here;
}
 
C

Chris Dollin

hyderabadblues said:
I have a doubt regarding how to access global variables if already
there is one static variable with the same name defined at the
beginning of file outside any function.

E.g:
//File client.c
int iGlobalVar; // Global Variable

// main.c

static int iGlobalVar;

int main()
{
// How to access iGlobalVar here;
}

In main.c, rename `iGlobalVar` to `someDecentName`.

PS there should be a `client.h` header file containing the extern
declaration for `iGlobalVar`, which you #include into `client.c`
and `main.c`.

PPS I hope `iGlobalVar` has a decent name too.
 
B

Ben Bacarisse

hyderabadblues said:
I have a doubt regarding how to access global variables if already
there is one static variable with the same name defined at the
beginning of file outside any function.

E.g:
//File client.c
int iGlobalVar; // Global Variable

// main.c

static int iGlobalVar;

int main()
{
// How to access iGlobalVar here;
}

I typed an answer and then deleted it thinking that this *must* be
homework. If it is not, the *real* answer is "don't do this" -- at
the very least you are creating a mystery for others reading the code
later.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top