D - function pointers
- Pavel Minayev (10/10) Dec 23 2001 Yes, I know it's not the first time this question is
- Walter (3/13) Dec 23 2001 At the moment they work like C function pointers. -Walter
- Pavel Minayev (3/4) Dec 23 2001 At the moment?.. Are you planning to change 'em?
- Walter (3/7) Dec 23 2001 Probably not. If it ain't broke ...
- Pavel Minayev (25/29) Dec 23 2001 Pretty bad... it doesn't suite the way other things are declared.
- Walter (5/35) Dec 24 2001 I have to rewrite the declaration parsing code anyway, I'll revisit it
- Pavel Minayev (4/4) Dec 23 2001 Also, I've noticed that there is no way to put extern()
- Walter (3/7) Dec 23 2001 The usual way to accomplish that is put the extern around a typedef.
- Pavel Minayev (3/4) Dec 24 2001 Is it already possible in latest alpha?
- Walter (3/7) Dec 24 2001 It should work.
Yes, I know it's not the first time this question is asked, still... what will be the syntax for function pointers in D? Will it be like in C (please, no!), or D-style when all type attributes are on the left... or whatever? The reason why I ask is that I've started messing with WinAPI headers, trying to convert them to D, so far I have a simple converter already but I need to know syntax for function pointers to bring it to working stage...
Dec 23 2001
At the moment they work like C function pointers. -Walter "Pavel Minayev" <evilone omen.ru> wrote in message news:a05amk$278o$1 digitaldaemon.com...Yes, I know it's not the first time this question is asked, still... what will be the syntax for function pointers in D? Will it be like in C (please, no!), or D-style when all type attributes are on the left... or whatever? The reason why I ask is that I've started messing with WinAPI headers, trying to convert them to D, so far I have a simple converter already but I need to know syntax for function pointers to bring it to working stage...
Dec 23 2001
"Walter" <walter digitalmars.com> wrote in message news:a05cv8$28l0$1 digitaldaemon.com...At the moment they work like C function pointers. -WalterAt the moment?.. Are you planning to change 'em?
Dec 23 2001
"Pavel Minayev" <evilone omen.ru> wrote in message news:a05gga$2b5c$1 digitaldaemon.com..."Walter" <walter digitalmars.com> wrote in message news:a05cv8$28l0$1 digitaldaemon.com...Probably not. If it ain't broke ...At the moment they work like C function pointers. -WalterAt the moment?.. Are you planning to change 'em?
Dec 23 2001
"Walter" <walter digitalmars.com> wrote in message news:a05jv9$2cuo$2 digitaldaemon.com...Pretty bad... it doesn't suite the way other things are declared. Both pointers and arrays in declaration are applied to type rather than to variable, why such a mess with functions? The syntax is clumsy and rather limited. How do I declare an array of function pointers? Or pointer to function that returns pointer to function? Or simply declare several pointers at once? Yes, this can be done with a typedef, I know, but with D-style syntax it would be even simplier: LRESULT(uint, HANDLE, WPARAM, LPARAM) OldWndProc; // declare function ptr void(int*)[10] ptrarray; // array of funcptrs void(int)(char[]) funcptr; // ptr to function that returns ptr to function char[]() a, b, c; // three pointers to function returning char[] Another problem with C-style syntax is typedefing and aliasing. The usual syntax is "typedef old-type new-type", the same with alias. However, function pointers are a mess here: typedef LRESULT (*WindowProc)(uint, HANDLE, WPARAM, LPARAM); It's not very easy to tell where is the "old" type and where is the "new" one by looking at this line quickly... D-style would be: typedef LRESULT(uint, HANDLE, WPARAM, LPARAM) WindowProc; Don't you think it's just better to parse, read, and understand?Probably not. If it ain't broke ...At the moment they work like C function pointers. -WalterAt the moment?.. Are you planning to change 'em?
Dec 23 2001
I have to rewrite the declaration parsing code anyway, I'll revisit it then. -Walter "Pavel Minayev" <evilone omen.ru> wrote in message news:a06pcm$9bk$1 digitaldaemon.com..."Walter" <walter digitalmars.com> wrote in message news:a05jv9$2cuo$2 digitaldaemon.com...functionPretty bad... it doesn't suite the way other things are declared. Both pointers and arrays in declaration are applied to type rather than to variable, why such a mess with functions? The syntax is clumsy and rather limited. How do I declare an array of function pointers? Or pointer to function that returns pointer to function? Or simply declare several pointers at once? Yes, this can be done with a typedef, I know, but with D-style syntax it would be even simplier: LRESULT(uint, HANDLE, WPARAM, LPARAM) OldWndProc; // declareProbably not. If it ain't broke ...At the moment they work like C function pointers. -WalterAt the moment?.. Are you planning to change 'em?ptr void(int*)[10] ptrarray; // array of funcptrs void(int)(char[]) funcptr; // ptr to function that returns ptr to function char[]() a, b, c; // three pointers to function returning char[] Another problem with C-style syntax is typedefing and aliasing. The usual syntax is "typedef old-type new-type", the same with alias. However, function pointers are a mess here: typedef LRESULT (*WindowProc)(uint, HANDLE, WPARAM, LPARAM); It's not very easy to tell where is the "old" type and where is the "new" one by looking at this line quickly... D-style would be: typedef LRESULT(uint, HANDLE, WPARAM, LPARAM) WindowProc; Don't you think it's just better to parse, read, and understand?
Dec 24 2001
Also, I've noticed that there is no way to put extern() into function pointer declaration. There should be a way to do that since all API callbacks are defined as stdcall.
Dec 23 2001
The usual way to accomplish that is put the extern around a typedef. "Pavel Minayev" <evilone omen.ru> wrote in message news:a05got$2b6c$1 digitaldaemon.com...Also, I've noticed that there is no way to put extern() into function pointer declaration. There should be a way to do that since all API callbacks are defined as stdcall.
Dec 23 2001
"Walter" <walter digitalmars.com> wrote in message news:a05jv8$2cuo$1 digitaldaemon.com...The usual way to accomplish that is put the extern around a typedef.Is it already possible in latest alpha?
Dec 24 2001
"Pavel Minayev" <evilone omen.ru> wrote in message news:a06pco$9bk$2 digitaldaemon.com..."Walter" <walter digitalmars.com> wrote in message news:a05jv8$2cuo$1 digitaldaemon.com...It should work.The usual way to accomplish that is put the extern around a typedef.Is it already possible in latest alpha?
Dec 24 2001