Thread overview | ||||||||
---|---|---|---|---|---|---|---|---|
|
November 21, 2020 spec: Function types | ||||
---|---|---|---|---|
| ||||
So a type declared using 'function' is actually a function pointer type. What is the type of a function in D? |
November 21, 2020 Re: spec: Function types | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dibyendu Majumdar | 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, 2020 Re: spec: Function types | ||||
---|---|---|---|---|
| ||||
Posted in reply to Paul Backus | 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, 2020 Re: spec: Function types | ||||
---|---|---|---|---|
| ||||
Posted in reply to Paul Backus | 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, 2020 Re: spec: Function types | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dibyendu Majumdar | 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, 2020 Re: spec: Function types | ||||
---|---|---|---|---|
| ||||
Posted in reply to Adam D. Ruppe | 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
|
Copyright © 1999-2021 by the D Language Foundation