How can a function pointer required to be extern(C)?

rempas rempas at tutanota.com
Thu Apr 13 07:30:27 UTC 2023


On Wednesday, 12 April 2023 at 20:36:59 UTC, H. S. Teoh wrote:
>
> IMO this is a bug either in D's syntax or in the parser.  I'd 
> file an enhancement request.
>
> In the meantime, you can use alias as a workaround:
>
>
> -------snip-------
> extern(C) void* abc(void*) {return null;}
>
> alias FuncPtr = typeof(&abc);
> pragma(msg, typeof(abc));
> pragma(msg, typeof(&abc));
>
> //void wrapper(extern(C) void* function(void*) callback) {} // 
> NG
> void wrapper(FuncPtr callback) {} // OK
>
> pragma(msg, typeof(wrapper));
> -------snip-------
>
>
> T

Thank you! As long as there is a way to do it with aliases, I 
don't think that there is a reason to even bother the developers. 
I mean, it will just save me 1 line of code in my whole project 
(because I don't think I'll use this even again somewhere else) 
so I don't think it's worth it. Thank you for your help. Best 
thing with Dlang is the community ;) I wish you to have an 
amazing day!



More information about the Digitalmars-d-learn mailing list