Bruce
Bruce

Reputation: 35255

How to differentiate between static global variable and extern global variable with same name?

I have 2 files:

file1.c:
static int k = 3;

file2.c
int k = 5

Is there any way to access the extern variable k inside file2.c?

Upvotes: 0

Views: 147

Answers (2)

rama
rama

Reputation: 1

Any variable is declared as a static variable, it can be accessed only with in a file or function. even if you declare extern int k also it cannot be accessed.

Upvotes: 0

Fred Foo
Fred Foo

Reputation: 363567

No, there is not. You should rename either one of your variables.

Upvotes: 3

Related Questions