Thread overview
November 21
So a type declared using 'function' is actually a function pointer type.

What is the type of a function in D?
November 21
On Saturday, 21 November 2020 at 00:26:45 UTC, Dibyendu Majumdar wrote:
> So a type declared using 'function' is actually a function pointer type.
>
> What is the type of a function in D?

int fun(int x);
pragma(msg, typeof(fun).stringof); // int(int x)
alias funType = int(int x);
static assert(is(funType == typeof(fun)));
November 21
On Saturday, 21 November 2020 at 00:42:06 UTC, Paul Backus wrote:
> On Saturday, 21 November 2020 at 00:26:45 UTC, Dibyendu Majumdar wrote:
>> So a type declared using 'function' is actually a function pointer type.
>>
>> What is the type of a function in D?
>
> int fun(int x);
> pragma(msg, typeof(fun).stringof); // int(int x)
> alias funType = int(int x);
> static assert(is(funType == typeof(fun)));

thanks
November 21
On Saturday, 21 November 2020 at 00:42:06 UTC, Paul Backus wrote:
> pragma(msg, typeof(fun).stringof); // int(int x)

pragma(msg, typeof(&fun).stringof);

prints:

int delegate(int x)

I was expecting:

int function(int x)



November 21
On Saturday, 21 November 2020 at 00:51:30 UTC, Dibyendu Majumdar wrote:
> pragma(msg, typeof(&fun).stringof);

If fun is nested it will be a delegate. Only if top-level or static will it be function.
November 21
On Saturday, 21 November 2020 at 00:57:10 UTC, Adam D. Ruppe wrote:
> On Saturday, 21 November 2020 at 00:51:30 UTC, Dibyendu Majumdar wrote:
>> pragma(msg, typeof(&fun).stringof);
>
> If fun is nested it will be a delegate. Only if top-level or static will it be function.

I see. Okay thanks