Thread overview | ||||||
---|---|---|---|---|---|---|
|
December 17, 2022 [Issue 2168] cast extern enhancement? | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=2168 Iain Buclaw <ibuclaw@gdcproject.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Priority|P2 |P4 -- |
July 02 [Issue 2168] cast extern enhancement? | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=2168 RazvanN <razvan.nitu1305@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |razvan.nitu1305@gmail.com --- Comment #3 from RazvanN <razvan.nitu1305@gmail.com> --- You can just declare the return type of wglGetProcAddress to be of type `int function()`: extern(C) int function() func(char*); And then it will work without needing the cast. -- |
July 02 [Issue 2168] cast extern enhancement? | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=2168 Dennis <dkorpel@live.nl> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |dkorpel@live.nl Hardware|x86 |All OS|Windows |All --- Comment #4 from Dennis <dkorpel@live.nl> --- (In reply to RazvanN from comment #3) > And then it will work without needing the cast. That works in this reduced example, but when doing dynamic loading, you often load multiple functions with different signatures. -- |
July 03 [Issue 2168] cast extern enhancement? | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=2168 --- Comment #5 from RazvanN <razvan.nitu1305@gmail.com> --- (In reply to Dennis from comment #4) > (In reply to RazvanN from comment #3) > > And then it will work without needing the cast. > > That works in this reduced example, but when doing dynamic loading, you often load multiple functions with different signatures. In that case, this seems to work: ``` extern(C) void* func(char*); void main() { char* p = cast(char*)"func".ptr; extern(C) int function() glFunctionFoo = cast(int function())func(p); extern(C) int function(int) glFunctionFoo2 = cast(int function(int))func(p); pragma(msg, typeof(glFunctionFoo)); pragma(msg, typeof(glFunctionFoo2)); } ``` So, forcing the lhs of the assignment to extern(C) enables the cast to work. -- |
Copyright © 1999-2021 by the D Language Foundation