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

FrankLike 1150015857 at qq.com
Wed Jan 30 06:02:02 UTC 2019


On Wednesday, 30 January 2019 at 05:40:50 UTC, FrankLike wrote:
> On Wednesday, 30 January 2019 at 05:14:20 UTC, 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?
>>
>> Thanks.

import std.stdio;
import std.process:executeShell;
import core.demangle;

void main()
{	
	assert(mangle!(int function(int))("a.b") == "_D1a1bPFiZi");
	executeShell("pause");
}
> ////////////////CODE END//////////
> Yes,"_D1a1bPFiZi",which includes "P".




More information about the Digitalmars-d-learn mailing list