Re: extern function declaration

Discussion in 'C++' started by Jim Fischer, Jul 17, 2003.

  1. Jim Fischer

    Jim Fischer Guest

    josef angermeier wrote:
    >
    > hi programmers
    > extern is used to change the binding. i also understand that the keyword
    > extern prevents a expression like "extern int a" to be an definition,
    > but what use does it have to declare a function as extern though
    > functions and variables by default have external binding ?. ("extern
    > void func();" == "void func();") != ( "static void func();" ==
    > "namespace{ void func();}") ?


    As an asside, if I recall correctly,

    "static void func();" != "namespace { void func(); }"

    Right? Specifically, if you specify

    static void func();

    then 'func()' has internal linkage WRT the current translation unit (see
    3.5/3). OTOH, if you specify,

    namespace { void func(); }

    then 'func()' has *external* linkage (see 3.5/4). HOWEVER: The name
    'func' is not visible outside the translation unit that declares the
    anonymous namespace (see 7.3.1.1). IOW, the name 'func' -- which has
    external linkage -- can only be referred to from scopes within the same
    translation unit that declares the anonymous namespace.

    Hopefully, someone who knows more about this will confirm/refute these
    comments...

    --
    Jim

    To reply by email, remove "link" and change "now.here" to "yahoo"
    jfischer_link5809{at}now.here.com
     
    Jim Fischer, Jul 17, 2003
    #1
    1. Advertising


  2. > btw to what are you refering with (eg. 7.3.1.1) some sort of C++ language
    > specific. ?? it doent seem to refer to bjarne stroustrup's c++ programming
    > language book chapters...


    He refers to the C++ standard (ISO/IEC 14882:1998).
     
    Josephine Schafer, Jul 17, 2003
    #2
    1. Advertising

  3. >
    > then 'func()' has *external* linkage (see 3.5/4). HOWEVER: The name
    > 'func' is not visible outside the translation unit that declares the
    > anonymous namespace (see 7.3.1.1). IOW, the name 'func' -- which has
    > external linkage -- can only be referred to from scopes within the same
    > translation unit that declares the anonymous namespace.


    ok i understand what you mean, the symbol is propably shown in the symbol
    table for external usage but for the namespace was used a arbitrary value
    so that the other translation unit can't find it (easily)! i think i
    understand :) maybe reading somewhere the exact definition of "linkage ...
    external linkage" would be good....
    btw to what are you refering with (eg. 7.3.1.1) some sort of C++ language
    specific. ?? it doent seem to refer to bjarne stroustrup's c++ programming
    language book chapters...

    thanks josef



    --
    Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
     
    josef angermeier, Jul 18, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. josef angermeier

    Re: extern function declaration

    josef angermeier, Jul 17, 2003, in forum: C++
    Replies:
    0
    Views:
    396
    josef angermeier
    Jul 17, 2003
  2. Andrey Tarasevich

    Re: extern function declaration

    Andrey Tarasevich, Jul 16, 2003, in forum: C++
    Replies:
    0
    Views:
    427
    Andrey Tarasevich
    Jul 16, 2003
  3. Thomas Matthews
    Replies:
    5
    Views:
    2,496
    tom_usenet
    Aug 2, 2004
  4. Andy
    Replies:
    2
    Views:
    1,611
    Matthew
    Jan 28, 2005
  5. Andre
    Replies:
    5
    Views:
    552
    Keith Thompson
    Jul 17, 2012
Loading...

Share This Page