Re: keyword extern

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


Date: 26 Jun 2004 01:10:42 -0700


> What's the best way to use extern when using multiplefiles that is
> easiest to maintain?

> Is it best to declare:
>
> extern int a;
>
> in a header file and include the header file in all files except
> where it's defined.

> Or is it better to write
>
> extern int a;
>
> in all the files except where it's originally defined?

One of the purposes of using extern in multiple files is restricting
the visibility of the variable only to the file that needs to "see"
it. 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.

sarma



Relevant Pages

  • 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 to debug Link errors of static LIB in eVC?
    ... extern "C" { ... directory of the header file which I had set. ... but your compiler finds somehow the C++ prototype of the function and generates the decorated name for the unresolved external. ... PPlugin_PSoundChannel_WAVFile_Registration_Instance that returns a PPlugin_PSoundChannel_WAVFile_Registration class object. ...
    (microsoft.public.windowsce.embedded.vc)
  • Re: alpha defined: virtualcnt,titleid,keyid,helplineid,pasteboardid
    ... > Where would I best find EXTERN and GLOBAL variables? ... Going back to the C sources: the definitions and (EXTERN) ... thus finding the header file. ... Another way would be to use the CTAGS program, which keeps trace ...
    (comp.os.vms)
  • Re: confused about extern use
    ... I read about extern that whenever we ... So the above style (whatever Nick have given as example) can be ... In the preprocessing operation header file will populate the c- ... extern struct abc abc_var1 ...
    (comp.lang.c)
  • Re: Getting function signature
    ... source code (or at least a declaration in a header file). ... if the function you're looking to call was declared as "extern ... name mangling is turned off (and you can't overload that ...
    (comp.lang.c)