How can I express the type of a function in D?

Steven Schveighoffer schveiguy at gmail.com
Thu Jan 31 02:04:39 UTC 2019


On 1/30/19 1:39 PM, Ali Çehreli wrote:
> On 01/30/2019 07:47 AM, Steven Schveighoffer wrote:
>  > On 1/30/19 12:14 AM, Sobaya wrote:
>  >> I want to get a mangled name of a D function by
>  >> `core.demangle.mangle`, but I'm in trouble because there are no ways
>  >> to express a type of a function, which is used for a template argument
>  >> of `mangle`.
>  >>
>  >> For example, it is wrong to use the type `int function(int,int)` to
>  >> express the type of `int add(int,int)`.
>  >> Because it expresses the type of a function POINTER, not just a 
> function.
>  >>
>  >> The fuction name in a binary compiled this function is "_D3addFiiZi",
>  >> but `mangle!(int function(int,int))("add")` returns "_D3addPFiiZi",
>  >> which includes "P" meaning POINTER.
>  >>
>  >> How can I get the former one?
>  >
>  > Why not use add.mangleof?
>  >
> 
> add.mangleof includes the module name as well (_D6deneme3addFiiZi) but 
> the OP wanted without (_D3addFiiZi). 

But he says `The fuction name in a binary compiled this function is 
"_D3addFiiZi"`. So whatever he compiles as must be what mangleof 
reports, as it's the same entity generating the mangle. I don't know 
what his source code is.

-Steve


More information about the Digitalmars-d-learn mailing list