Re: keyword extern

umbs.sairam_at_gmail.com
Date: 06/26/04


Date: 26 Jun 2004 09:10:08 -0700


> > In your question, in both the cases the variable "a" is visible in
> > all the files. In such a situation, there is no benefit in using the
> > keyword "extern. You might as well declare the variable as global.
>
> Sorry, I failed to understand your point. 'extern' doesn't make global a
> variable. It's the lack of 'static' that makes it.

I am sorry if I did not explain myself clearly. If we have the
following files
(pseudo-code)

head.h
/* common to all files */

head1.h
/* used in file1.c */

file1.c
include "head.h"
include "head1.h"
/* code of file1.c */
.....

headN.h
/* used in fileN.c */

fileN.c
include "head.h"
include "headN.h"
/* code of fileN.c */

Now, declare a variable in head1.h as int i and define it in file1.c
as i = 10. My argument in the above post is, if "i" is declared
multiple times using extern in all the files file2.c ... fileN.c then
the significance of "extern"ing is lost. The programmer could have
acheived the same functionality by declaring the variable in head.h

sarma



Relevant Pages

  • Re: const and extern...
    ... extern float bar; ... a declaration), but if you merely declare it, you do not define it. ... or the translation unit ends. ... an actual definition with an initializer of: ...
    (comp.lang.c)
  • Re: confused about extern use
    ... going to achieve by declaring it as extern in the header file a.h. ... composed on one or more compilation units. ... Essentially you *declare* the type wherever it is ...
    (comp.lang.c)
  • Re: How do header files work?
    ... declare some constants, variables, and functions that have ... for is the "extern" linkage keyword (which nobody has mentioned ... following source files in my directory: ... That's because the compiler for your library.c file doesn't need ...
    (comp.lang.c)
  • Re: Exported function mangaled name
    ... extern "C" { ... You have otherwise defined a function unrelated to the header ... You have to declare the function the same way in your .cpp file as in your .h file ... #define LIBSPEC __declspec ...
    (microsoft.public.vc.mfc)
  • Re: keyword extern
    ... > declared multiple times using extern in all the files file2.c ... NEVER, ever, define a variable in a header file. ... declare it with the "extern" qualifier in the header file for the ... misuse. ...
    (comp.lang.c)