mangle

Justin Spahr-Summers Justin.SpahrSummers at gmail.com
Sun Jul 4 10:23:07 PDT 2010


On Fri, 02 Jul 2010 08:41:45 -0400, Steven Schveighoffer 
<schveiguy at yahoo.com> wrote:
> 
> On Thu, 01 Jul 2010 23:03:31 -0400, Justin Spahr-Summers  
> <Justin.SpahrSummers at gmail.com> wrote:
> 
> > On Thu, 1 Jul 2010 19:34:09 -0700, Jonathan M Davis
> > <jmdavisprog at gmail.com> wrote:
> >>
> >> On Thursday, July 01, 2010 19:13:02 Rainer Deyke wrote:
> >> > On 7/1/2010 19:32, Jonathan M Davis wrote:
> >> > > By the way, why _does_ D mangle its names? What's the advantage? I
> >> > > understood that C++ does it because it was forced to back in the  
> >> days
> >> > > when it was transformed into C code during compilation but that  
> >> it's now
> >> > > generally considered a legacy problem that we're stuck with rather  
> >> than
> >> > > something that would still be considered a good design decision.
> >> > >
> >> > > So, why did D go with name mangling? It certainly makes stuff like  
> >> stack
> >> > > traces harder to deal with. I've never heard of any advantage to  
> >> name
> >> > > mangling, only disadvantages.
> >> >
> >> > Because DMD is stuck with a C-age linker.
> >>
> >> Well, I guess that it just goes to show how little I understand about  
> >> exactly
> >> how linking works when I don't understand what that means. After all, C  
> >> doesn't
> >> using name mangling. Does that mean that name mangling it meant as a  
> >> namespacing
> >> tool to ensure that no D function could possibly have the same linking  
> >> name as a
> >> C function?
> >>
> >> - Jonathan M Davis
> >
> > C doesn't require mangling because functions can't be overloaded. To
> > make D (or C++) compatible with C linkers, symbol names need to be
> > unique, so functions with identical names but different types need to be
> > represented with different symbols.
> 
> This isn't really the reason for "mangling".  The issue is that the C  
> linker requires symbols to be the same as source symbols.  That is, made  
> up only of A-Z,a-z,0-9 and _.  I'd much rather see symbol names like this:
> 
> foo(int,string)
> 
> than
> 
> fooIvS45whatever
> 
> -Steve

Right, but that's only an issue because of overloaded types. C suffers 
no such problems because a symbol with a given name is guaranteed to be 
unique within the same translation unit.


More information about the Digitalmars-d mailing list