Re: confused about extern use
- From: "Lalatendu Das" <lalatdas@xxxxxxxxx>
- Date: 21 Feb 2007 20:01:08 -0800
Hi all,
I really appreciate all answers relating to the post particularly
of Mr Nick Keighley.
it is very lucid to understand. And I am sorry for using
abbreviations like "u".
But still I have some doubt. I read about extern that whenever we
need to use the same global
variable across different C-files we need to use extern keyword
and declare it so that it will
refer to same variable where it got defined.
So the above style ( whatever Nick have given as example) can be
re-written like define the
structure in the header-file. i.e
just struct abc {
int a;
int b;
};
Then define a variable of the structure in the required C-
file and in above case in file-1.c
as : struct abc abc_var1; //as a global variable. Then If u
want to use it in another C-file
file-2.c we can sdeclare as: extern struct abc abc_var1; //It
will refer to the abc_var1 of file1.c
I can understand that whatever Nick explained the same thing will
happen (If I am not wrong)
In the preprocessing operation header file will populate the c-
file with the extern declaration.
But I think in file-1.c the extern declaration and the defination
of variable both will apear
after preprocessing header file. i.e
extern struct abc abc_var1
struct abc abc_var1
Is this not a problem.Though not a error but We can avoid this
by define the structure in a header file and then define a variable of
the structure type in a c-file then use extern keyword to refer to the
same variable wherever we want. This solves the whole purpose what we
can achieve out of
doing in the manner Mick replied or i have posted in the querry.
Thanks
Das
.
- Follow-Ups:
- Re: confused about extern use
- From: Ian Collins
- Re: confused about extern use
- References:
- confused about extern use
- From: Lalatendu Das
- Re: confused about extern use
- From: Ian Collins
- Re: confused about extern use
- From: Lalatendu Das
- Re: confused about extern use
- From: Nick Keighley
- confused about extern use
- Prev by Date: Re: printf anomaly
- Next by Date: Re: printf anomaly
- Previous by thread: Re: confused about extern use
- Next by thread: Re: confused about extern use
- Index(es):
Relevant Pages
|