C++

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

    C++

    Hi,
    can somebody explore me more on Concept of Name Mangling used by C+
    + compilers.Also what is is the concept of UNICODES & what are
    TRIGRAPH SEQUENCES.

    Regards,

    Chambu
  • James Kanze

    #2
    Re: C++

    On Feb 23, 5:28 am, chambu <vishal9mhamun. ..@yahoo.co.inw rote:
    can somebody explore me more on Concept of Name Mangling
    used by C++ compilers.
    An implementation detail, which varies from one compiler to the
    next.
    Also what is is the concept of UNICODES
    www.unicode.org. Also the first five chapters of _Fontes_ _et_
    _codages_, by Yannis Haralambous. (An English translation, and
    probably others, is available.)
    & what are
    TRIGRAPH SEQUENCES.
    Something you don't want to know about. A solution to a problem
    that had ceased to exist by the time they were implemented.
    (See http://www.gotw.ca/gotw/086.htm, for example.)

    --
    James Kanze (GABI Software) email:james.kan ze@gmail.com
    Conseils en informatique orientée objet/
    Beratung in objektorientier ter Datenverarbeitu ng
    9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

    Comment

    • Juha Nieminen

      #3
      Re: C++

      James Kanze wrote:
      > can somebody explore me more on Concept of Name Mangling
      > used by C++ compilers.
      >
      An implementation detail, which varies from one compiler to the
      next.
      Which is a shame, really. It hinders C++'s capabilities at creating
      shared and precompiled libraries. Either all C++ shared/precompiled
      libraries and C++ programs in a system must be compiled with the same
      compiler, or if several different compilers are used, they all must use
      the exact same name mangling system which, as you say, is often not the
      case.

      If name mangling was standardized, it would greatly increase the
      usability of C++ to create shared and precompiled libraries usable among
      different compilers.

      If I'm not mistaken, in the C world name mangling has been long ago
      "standardiz ed" (if not de jure, at least de facto), which is why C is so
      much more usable for precompiled libraries: A library created by any C
      compiler is usable by any another C (and even C++) compiler.

      Comment

      • Rolf Magnus

        #4
        Re: C++

        Juha Nieminen wrote:
        James Kanze wrote:
        >> can somebody explore me more on Concept of Name Mangling
        >> used by C++ compilers.
        >>
        >An implementation detail, which varies from one compiler to the
        >next.
        >
        Which is a shame, really. It hinders C++'s capabilities at creating
        shared and precompiled libraries.
        There are a lot more things to consider for that than just name mangling.
        Either all C++ shared/precompiled libraries and C++ programs in a system
        must be compiled with the same compiler, or if several different compilers
        are used, they all must use the exact same name mangling system which, as
        you say, is often not the case.
        >
        If name mangling was standardized, it would greatly increase the
        usability of C++ to create shared and precompiled libraries usable among
        different compilers.
        >
        If I'm not mistaken, in the C world name mangling has been long ago
        "standardiz ed" (if not de jure, at least de facto),
        Even though C wouldn't actually need any name mangling at all, it is in fact
        not "standardiz ed", at least not under all systems. I have found that out
        lately when I needed to write a DLL for Windows that can be used as a
        drop-in replacement for an old one.

        Comment

        • Pete Becker

          #5
          Re: C++

          On 2008-02-23 07:14:51 -0500, Juha Nieminen <nospam@thanks. invalidsaid:
          >
          If name mangling was standardized, it would greatly increase the
          usability of C++ to create shared and precompiled libraries usable among
          different compilers.
          >
          Name mangling is one of several problems in getting different compilers
          to work together. You also need to agree on object layout, calling
          conventions, and, perhaps, register usage. These are all platform
          specific, so there's no universal solution that handles all of them.
          If I'm not mistaken, in the C world name mangling has been long ago
          "standardiz ed" (if not de jure, at least de facto), which is why C is so
          much more usable for precompiled libraries: A library created by any C
          compiler is usable by any another C (and even C++) compiler.
          Back when I was paying attention to it, many C compilers mangled names
          by putting an underscore at the beginning of the name. Some put it at
          the end. Some just used the name itself. And libraries created by any C
          compiler could be used by any other C compiler only to the extent that
          vendors agreed on name mangling, object layout, and calling conventions.

          --
          Pete
          Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
          Standard C++ Library Extensions: a Tutorial and Reference
          (www.petebecker.com/tr1book)

          Comment

          • Jeff Schwab

            #6
            Re: C++

            Rolf Magnus wrote:
            Juha Nieminen wrote:
            ....
            > If I'm not mistaken, in the C world name mangling has been long ago
            >"standardize d" (if not de jure, at least de facto),
            >
            Even though C wouldn't actually need any name mangling at all it is in fact
            not "standardiz ed", at least not under all systems. I have found that out
            lately when I needed to write a DLL for Windows that can be used as a
            drop-in replacement for an old one.
            What kind of mismatch did you see? I though each externally linked C
            identifiers in Windows object files had exactly one leading underscore,
            followed by the C identifier.

            Comment

            • Rolf Magnus

              #7
              Re: C++

              Jeff Schwab wrote:
              Rolf Magnus wrote:
              >Juha Nieminen wrote:
              ...
              >> If I'm not mistaken, in the C world name mangling has been long ago
              >>"standardized " (if not de jure, at least de facto),
              >>
              >Even though C wouldn't actually need any name mangling at all it is in
              >fact not "standardiz ed", at least not under all systems. I have found
              >that out lately when I needed to write a DLL for Windows that can be used
              >as a drop-in replacement for an old one.
              >
              What kind of mismatch did you see?
              About what is described here: http://www.geocities.com/yongweiwu/stdcall.htm
              I though each externally linked C identifiers in Windows object files had
              exactly one leading underscore, followed by the C identifier.
              It seems that this is the case only as long as you don't use dynamically
              linked libraries, and even then you can't be sure of that, considering the
              comment below the table on that web page.


              Comment

              • Rolf Magnus

                #8
                Re: C++

                Pete Becker wrote:
                On 2008-02-23 07:14:51 -0500, Juha Nieminen <nospam@thanks. invalidsaid:
                >
                >>
                > If name mangling was standardized, it would greatly increase the
                >usability of C++ to create shared and precompiled libraries usable among
                >different compilers.
                >>
                >
                Name mangling is one of several problems in getting different compilers
                to work together. You also need to agree on object layout, calling
                conventions, and, perhaps, register usage.
                Don't forget things like exception handling and details like dynamic
                initialization of global objects or NRVO. And then, there is the standard
                library. If name mangling is the same, you can't link standard libraries of
                two different compilers together, but each compiler uses its own headers,
                so I wouldn't expect code compiled to run with one standard library
                implementation to work with another.
                These are all platform specific, so there's no universal solution that
                handles all of them.
                I'd say most parts don't really need to be different for different
                platforms. There even is a more-or-less-standard ABI, but there are just a
                lot of compilers that don't support it.

                Comment

                • Juha Nieminen

                  #9
                  Re: C++

                  Pete Becker wrote:
                  On 2008-02-23 07:14:51 -0500, Juha Nieminen <nospam@thanks. invalidsaid:
                  > If name mangling was standardized, it would greatly increase the
                  >usability of C++ to create shared and precompiled libraries usable among
                  >different compilers.
                  >
                  Name mangling is one of several problems in getting different compilers
                  to work together. You also need to agree on object layout, calling
                  conventions, and, perhaps, register usage. These are all platform
                  specific, so there's no universal solution that handles all of them.
                  Precompiled libraries are platform specific. That wasn't the point.

                  What I meant was that I can create a precompiled or even a dynamically
                  loadable shared library in C with gcc and use it in code I'm compiling
                  using icc (or basically any other C compiler for the same system).

                  C++ has this problem that a precompiled library created with one
                  compiler may not be usable with another. In some cases it might not even
                  be usable with the next version of the *same* compiler! This is because
                  compilers don't seem to yet agree on which name mangling convention to use.

                  Comment

                  • Jeff Schwab

                    #10
                    Re: C++

                    Rolf Magnus wrote:
                    Jeff Schwab wrote:
                    >
                    >Rolf Magnus wrote:
                    >>Juha Nieminen wrote:
                    >...
                    >>> If I'm not mistaken, in the C world name mangling has been long ago
                    >>>"standardize d" (if not de jure, at least de facto),
                    >>Even though C wouldn't actually need any name mangling at all it is in
                    >>fact not "standardiz ed", at least not under all systems. I have found
                    >>that out lately when I needed to write a DLL for Windows that can be used
                    >>as a drop-in replacement for an old one.
                    >What kind of mismatch did you see?
                    >
                    About what is described here: http://www.geocities.com/yongweiwu/stdcall.htm
                    >
                    >I though each externally linked C identifiers in Windows object files had
                    >exactly one leading underscore, followed by the C identifier.
                    >
                    It seems that this is the case only as long as you don't use dynamically
                    linked libraries, and even then you can't be sure of that, considering the
                    comment below the table on that web page.
                    Thanks for the link. Good to know!

                    Comment

                    • Pete Becker

                      #11
                      Re: C++

                      On 2008-02-23 09:56:14 -0500, Rolf Magnus <ramagnus@t-online.desaid:
                      Pete Becker wrote:
                      >
                      >On 2008-02-23 07:14:51 -0500, Juha Nieminen <nospam@thanks. invalidsaid:
                      >>
                      >>>
                      >>If name mangling was standardized, it would greatly increase the
                      >>usability of C++ to create shared and precompiled libraries usable among
                      >>different compilers.
                      >>>
                      >>
                      >Name mangling is one of several problems in getting different compilers
                      >to work together. You also need to agree on object layout, calling
                      >conventions, and, perhaps, register usage.
                      >
                      Don't forget things like exception handling and details like dynamic
                      initialization of global objects or NRVO. And then, there is the standard
                      library. If name mangling is the same, you can't link standard libraries of
                      two different compilers together, but each compiler uses its own headers,
                      so I wouldn't expect code compiled to run with one standard library
                      implementation to work with another.
                      I *knew* there were things that I hadn't thought of. Thanks for filling
                      in more details.

                      --
                      Pete
                      Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
                      Standard C++ Library Extensions: a Tutorial and Reference
                      (www.petebecker.com/tr1book)

                      Comment

                      • Pete Becker

                        #12
                        Re: C++

                        On 2008-02-23 10:31:42 -0500, Juha Nieminen <nospam@thanks. invalidsaid:
                        Pete Becker wrote:
                        >On 2008-02-23 07:14:51 -0500, Juha Nieminen <nospam@thanks. invalidsaid:
                        >>If name mangling was standardized, it would greatly increase the
                        >>usability of C++ to create shared and precompiled libraries usable among
                        >>different compilers.
                        >>
                        >Name mangling is one of several problems in getting different compilers
                        >to work together. You also need to agree on object layout, calling
                        >conventions, and, perhaps, register usage. These are all platform
                        >specific, so there's no universal solution that handles all of them.
                        >
                        Precompiled libraries are platform specific. That wasn't the point.
                        >
                        What I meant was that I can create a precompiled or even a dynamically
                        loadable shared library in C with gcc and use it in code I'm compiling
                        using icc (or basically any other C compiler for the same system).
                        And that's because the vendors of gcc and icc, through some process
                        outside the C++ standard, agreed on all the details that are needed to
                        make that happen. Having the C++ standard define name mangling wouldn't
                        do that.
                        >
                        C++ has this problem that a precompiled library created with one
                        compiler may not be usable with another. In some cases it might not even
                        be usable with the next version of the *same* compiler! This is because
                        compilers don't seem to yet agree on which name mangling convention to use.
                        Again: it's not name mangling. In fact, differences in name mangling
                        are a good thing here: if everyone mangled names the same way, you'd be
                        able to link libraries that were not, in fact, compatible.

                        --
                        Pete
                        Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
                        Standard C++ Library Extensions: a Tutorial and Reference
                        (www.petebecker.com/tr1book)

                        Comment

                        • James Kanze

                          #13
                          Re: C++

                          On Feb 23, 3:56 pm, Rolf Magnus <ramag...@t-online.dewrote:
                          Pete Becker wrote:
                          On 2008-02-23 07:14:51 -0500, Juha Nieminen
                          <nos...@thanks. invalidsaid:
                          If name mangling was standardized, it would greatly
                          increase the usability of C++ to create shared and
                          precompiled libraries usable among different compilers.
                          Name mangling is one of several problems in getting
                          different compilers to work together. You also need to agree
                          on object layout, calling conventions, and, perhaps,
                          register usage.
                          Don't forget things like exception handling and details like
                          dynamic initialization of global objects or NRVO. And then,
                          there is the standard library. If name mangling is the same,
                          you can't link standard libraries of two different compilers
                          together, but each compiler uses its own headers, so I
                          wouldn't expect code compiled to run with one standard library
                          implementation to work with another.
                          Note that both of the compilers I regularly use (Sun CC and
                          g++) have two variants of the standard library; which one gets
                          used depends on invocation options. And the variants aren't
                          compatible. And don't affect name mangling. (I've already
                          spent some time tracking down errors in programs compiled with
                          g++ because the main code was compiled with -D_GLIBCXX_DEBUG et
                          al., but one of the libraries wasn't; I suspect that you would
                          get the same problems with Sun CC using -library=stlport 4 or
                          not. (And I think VC++ has similar problems.)
                          These are all platform specific, so there's no universal
                          solution that handles all of them.
                          I'd say most parts don't really need to be different for
                          different platforms. There even is a more-or-less-standard
                          ABI, but there are just a lot of compilers that don't support
                          it.
                          There is a standard ABI for one platform, I think. There's
                          certainly not one for Sparc, nor for Windows. (And for Windows
                          on a PC, there's only an informal one: what g++ uses.)

                          --
                          James Kanze (GABI Software) email:james.kan ze@gmail.com
                          Conseils en informatique orientée objet/
                          Beratung in objektorientier ter Datenverarbeitu ng
                          9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

                          Comment

                          • Rolf Magnus

                            #14
                            Re: C++

                            Alf P. Steinbach wrote:
                            * James Kanze:
                            >>
                            >There is a standard ABI for one platform, I think.
                            >
                            Not sure which one you're referring to.
                            Probably this one: http://www.codesourcery.com/cxx-abi/abi.html
                            AFAIK, g++ (and probably other compilers) uses this as basis on other
                            platforms too.
                            > There's certainly not one for Sparc, nor for Windows. (And for Windows
                            >on a PC, there's only an informal one: what g++ uses.)
                            >
                            Windows has two (platform-) standard ABIs, namely COM and .NET.
                            Is COM a C++ ABI? I thought it's just an object model based on C.
                            For .NET the situation isn't quite that bad because .NET is a more
                            modern VM-based ABI. However, also for .NET, language extensions are
                            key to managing the inherent complexity as seen from the C++ level. And
                            Microsoft defines 2 sets of such language extensions: "Managed
                            Extensions" for .NET is the older one, and "C++/CLI", essentially a new
                            /language/ that is a superset of C++, is the currently favored one.
                            I have no idea why anyone would use "C++/CLI". Either use real C++, or use
                            C#. Essentially "C++/CLI" looks to me like C# pressed into a syntax that is
                            closer to C++, but isn't really C++.
                            The C++/CLI language is essentially the brainchild of the chair of the
                            international C++ standardization committee Herb Sutter (he was the lead
                            architect), plus, .NET isn't completely restricted to Windows (the Mono
                            project, sponsored by Novell, "provides the necessary software to
                            develop and run .NET client and server applications on Linux, Solaris,
                            Mac OS X, Windows, and Unix"), so I don't think we should forget .NET as
                            C++ ABI, even though .NET is language independent.
                            It will never become "the single C++ ABI", considering that it's not based
                            on translating the C++ source code directly to native code.

                            Comment

                            Working...