www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - spec: Function types

reply Dibyendu Majumdar <mobile majumdar.org.uk> writes:
So a type declared using 'function' is actually a function 
pointer type.

What is the type of a function in D?
Nov 20 2020
parent reply Paul Backus <snarwin gmail.com> writes:
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)));
Nov 20 2020
next sibling parent Dibyendu Majumdar <mobile majumdar.org.uk> writes:
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
Nov 20 2020
prev sibling parent reply Dibyendu Majumdar <mobile majumdar.org.uk> writes:
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)
Nov 20 2020
parent reply Adam D. Ruppe <destructionator gmail.com> writes:
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.
Nov 20 2020
parent Dibyendu Majumdar <mobile majumdar.org.uk> writes:
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
Nov 20 2020