Re: how to use the keyword extern in c?

From: ooze (fjpan_at_163.net)
Date: 08/25/04


Date: 25 Aug 2004 07:39:53 -0700

Jack Klein <jackklein@spamcop.net> wrote in message news:<ti1oi0pucb87tneidrgt50hacnbjlfk9rt@4ax.com>...
> On 24 Aug 2004 19:15:30 -0700, fjpan@163.net (ooze) wrote in
> comp.lang.c:
>
> > hi all ,
> > anyone could tell me the useage of the keyworkd "extern" in c?
>
> The extern keyword specifies that the identifier being declared has
> external linkage. This allows an object or function to be defined in
> one translation unit (basically, source file and everything it
> includes) and referred to by name from code in other translation
> units.
>
> > and
> > the difference between c & cplusplus?
>
> C++ is off-topic here, news:comp.lang.c++ is down the hall to the
> right.
>
> > in the C99Rationalv5.10.pdf it lists 4 cases. while the first
> > common cases will incur the vc compiler to complain.
>
> As to what Visual C++ might complain about, it might make a difference
> whether you are using it as a C or C++ compiler, as it handles both
> languages.
>
> The document you reference is not necessarily one that many people
> have.
>
> Even for those who do, like I do, your reference is far too vague.
> The document is well over 200 pages, and the word 'extern' appears
> many times. I spent a brief time looking in both the PDF and printed
> versions I have, and did not find the section you are referring to.
>
> Post again and include the specific section number from the document.
> That is, if you are indeed compiling C code and not C++. And for
> readers here who do not have a copy of the rationale, copy and paste
> the code sample you are referring to, and copy and paste the compiler
> or linker error messages as well.

hallo,

in section 6.2.2 Linkages of identifiers
there is a table listed the 4 cases also includes detail info.

what's the difference when the keyword "extern" appears and when it doest appear?
for instance,
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 extern int var1; | int var1;
_____________________________________________________________
extern int var1 = 0x0bad | int var1 = 0x0bad
_____________________________________________________________
extern void func(); | void func();
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

in a c file.



Relevant Pages

  • Re: how to use the keyword extern in c?
    ... > The extern keyword specifies that the identifier being declared has ... > external linkage. ... > includes) and referred to by name from code in other translation ... what's the difference when the keyword "extern" appears and when it doest appear? ...
    (comp.lang.c)
  • Re: How to eliminate this global variable, silent?
    ... means "variable with static storage duration". ... not to the identifier of the object. ... The you provide the extern ...
    (comp.lang.c)
  • Re: "extern" meaning
    ... >> extern int A; ... external linkage of an identifier ... > in all translation units. ... think of it this way: when 'extern' is included ...
    (comp.lang.c)
  • Re: Pointer to extern char?
    ... How can there be a pointer to extern char? ... that the function has external linkage? ... static int a, *b, c; ... linkage when a declaration occurs at file scope, ...
    (comp.lang.c)
  • Re: extern
    ... The extern keyword usually gives you external ... % grep var a.c b.c ... Both have external linkage, but the "extern" in b.c inhibits ... "common block of size sizeof" will see the Fortran COMMON ...
    (comp.lang.c)