C++ linkage problems

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Web Developer

    C++ linkage problems

    Hi,

    I read that identifiers should not start with an underscore in order to
    prevent LINKAGE problems. I am not familar with this concept of "linkage",
    so can someone provide a simple explanation?

    Thanks in advance

    WD



    ---
    Outgoing mail is certified Virus Free.
    Checked by AVG anti-virus system (http://www.grisoft.com).
    Version: 6.0.504 / Virus Database: 302 - Release Date: 24/07/2003


  • Greg Comeau

    #2
    Re: C++ linkage problems

    In article <3f27b0a9_1@new s.iprimus.com.a u>,
    Web Developer <nospam@hotmail .com> wrote:[color=blue]
    >I read that identifiers should not start with an underscore in order to
    >prevent LINKAGE problems.[/color]

    The strongest argument is that there are rules in the standard
    that in a nushell say such names are only available for implementors,
    in other words, for your compiler or library vendor.
    [color=blue]
    > I am not familar with this concept of "linkage",
    >so can someone provide a simple explanation?[/color]

    Generally speaking, linkage applies to names of entities and
    is one mechanism whereby implementations can disabmiguate their use.
    In particular, when it needs to resolve where to uses of a name
    refers to the same name. For instance, in external linkage,
    the use of a "global" name in one translation unit (say a source file)
    is considered to be the same name used in another translation
    unit that will be linked together. It ties into scope and some
    other things too. There is also static linkage and no linkage.
    You should get a good C++ text and check out the section that
    apply to this topics you raise in this email. Check out
    http://www.comeaucomputing.com/booklist as one starting point.
    --
    Greg Comeau/ 4.3.0.1: FULL CORE LANGUAGE, INCLUDING TC1
    Comeau C/C++ ONLINE ==> http://www.comeaucomputing.com/tryitout
    World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
    Comeau C/C++ with Dinkumware's Libraries... Have you tried it?

    Comment

    • Greg Comeau

      #3
      Re: C++ linkage problems

      In article <ajPVa.13844$E3 3.3858530427@ne wssvr10.news.pr odigy.com>,
      Thomas Matthews <Thomas_Matthew sHatesSpamBots@ sbcglobal.net> wrote:[color=blue]
      >On one hand, there is no restriction against using symbols with leading
      >underscores... .[/color]

      I think you mean trailing?
      --
      Greg Comeau/ 4.3.0.1: FULL CORE LANGUAGE, INCLUDING TC1
      Comeau C/C++ ONLINE ==> http://www.comeaucomputing.com/tryitout
      World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
      Comeau C/C++ with Dinkumware's Libraries... Have you tried it?

      Comment

      • Thomas Matthews

        #4
        Re: C++ linkage problems

        Greg Comeau wrote:
        [color=blue]
        > In article <ajPVa.13844$E3 3.3858530427@ne wssvr10.news.pr odigy.com>,
        > Thomas Matthews <Thomas_Matthew sHatesSpamBots@ sbcglobal.net> wrote:
        >[color=green]
        >>On one hand, there is no restriction against using symbols with leading
        >>underscores.. ..[/color]
        >
        >
        > I think you mean trailing?[/color]

        No, I meant leading. A C++ compliant compiler will not generate
        an error for the following line:
        int __my_var;
        provided that the defined variable doesn't exist as a public
        symbol in the compiler's internals.

        However, there may be a problem with the following definition:
        int __FILE__;
        Because __FILE__ is used by the compiler (actually the preprocessor).

        --
        Thomas Matthews

        C++ newsgroup welcome message:

        C++ Faq: http://www.parashift.com/c++-faq-lite
        C Faq: http://www.eskimo.com/~scs/c-faq/top.html
        alt.comp.lang.l earn.c-c++ faq:

        Other sites:
        http://www.josuttis.com -- C++ STL Library book

        Comment

        • Greg Comeau

          #5
          Re: C++ linkage problems

          In article <5XRVa.13863$YW 4.3866168435@ne wssvr10.news.pr odigy.com>,
          Thomas Matthews <Thomas_Matthew sHatesSpamBots@ sbcglobal.net> wrote:[color=blue]
          >Greg Comeau wrote:[color=green]
          >> In article <ajPVa.13844$E3 3.3858530427@ne wssvr10.news.pr odigy.com>,
          >> Thomas Matthews <Thomas_Matthew sHatesSpamBots@ sbcglobal.net> wrote:[color=darkred]
          >>>On one hand, there is no restriction against using symbols with leading
          >>>underscores. ...[/color]
          >>
          >> I think you mean trailing?[/color]
          >
          >No, I meant leading. A C++ compliant compiler will not generate
          >an error for the following line:
          > int __my_var;
          >provided that the defined variable doesn't exist as a public
          >symbol in the compiler's internals.[/color]

          2.10 and 17.4.3.1.2 clearly label this as a restriction.
          Of course, certain "errors" need not result in a diagnostic,
          but that's a seperate issue.
          [color=blue]
          >However, there may be a problem with the following definition:
          > int __FILE__;[/color]

          Agreed. See above.
          [color=blue]
          >Because __FILE__ is used by the compiler[/color]

          s/used/may be used/

          Because __FILE__ begins with two underscores, and Standard C++
          reads "Each name that contains a double underscore (_ _) ...
          is reserved to the implementation for any use."
          [color=blue]
          >(actually the preprocessor).[/color]

          Perhaps.
          --
          Greg Comeau/ 4.3.0.1: FULL CORE LANGUAGE, INCLUDING TC1
          Comeau C/C++ ONLINE ==> http://www.comeaucomputing.com/tryitout
          World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
          Comeau C/C++ with Dinkumware's Libraries... Have you tried it?

          Comment

          • Web Developer

            #6
            Re: C++ linkage problems


            [color=blue]
            > Web Developer wrote:[color=green]
            > > Hi,
            > >
            > > I read that identifiers should not start with an underscore in order to
            > > prevent LINKAGE problems. I am not familar with this concept of[/color][/color]
            "linkage",[color=blue][color=green]
            > > so can someone provide a simple explanation?[/color]
            >
            > Symbols starting with an underscore are reserved for the compiler or
            > implementation. A programmer's symbol should not start with an
            > underscore to prevent name clashes or conflicts with compiler symbols.[/color]


            What do you mean by implementation?


            WD



            ---
            Outgoing mail is certified Virus Free.
            Checked by AVG anti-virus system (http://www.grisoft.com).
            Version: 6.0.504 / Virus Database: 302 - Release Date: 24/07/2003


            Comment

            Working...