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

Neia Neutuladh neia at ikeran.org
Wed Jan 30 19:51:17 UTC 2019


On Wed, 30 Jan 2019 10:39:21 -0800, Ali Çehreli wrote:
> import core.demangle;
> 
> extern(C) int add(int, int);
> 
> void main() {
>    alias F = typeof(add);
>    pragma(msg, mangle!F("add"));
>    pragma(msg, add.mangleof);
> }
> 
> Output:
> 
> _D3addUiiZi
> add               <-- Is that correct?

`add.mangleof` is correct. In fact, it's definitively correct.

typeof(add) is extern(C) int function(int, int). Based on this output, 
core.demangle seems like it's not taking the extern(C) portion into 
account.


More information about the Digitalmars-d-learn mailing list