Name Mangling & its representation of D types

Mike Parker aldacron at gmail.com
Tue Aug 3 16:55:55 UTC 2021


On Tuesday, 3 August 2021 at 16:43:52 UTC, NonNull wrote:
> I'd like to understand how any D type is represented as a 
> string by the name mangling done by the compilers.
>
> Does this always have the desirable property that different 
> types have different mangled names, so that a type is 
> faithfully represented by its mangled string incorporated into 
> a symbol name in an object file?
>
> What is that representation of a type as a string, and how does 
> it work for recursive types like a struct containing a pointer 
> to a struct of the same type?
>
> Please explain.

Name mangling applies to function parameters, as described here:

https://forum.dlang.org/thread/akshntlfahjpknsxdrdv@forum.dlang.org

Type names aren't mangled. They have a Fully Qualified Name (FQN) 
which is constructed from package(s), module, parent.

So for example:

```d
module mypack.mymod;

import std.stdio;

struct S
{
     struct Is {}
}

void main()
{
     writeln(typeid(S));
     writeln(typeid(S.Is));
}
```

This prints:

```
mypack.mymod.S
mypack.mymod.S.Is
```


More information about the Digitalmars-d-learn mailing list