I'm not sure where this nntp://news.digitalmars.com/digitalmars.D.bugs:2556 links.
But seems this test case gets lost?
http://dstress.kuehne.cn/dstress/trunk/compile/extern_07.d
module dstress.compile.extern_07;
extern(C) void *wglGetProcAddress(char*);
extern(C) int function() glFunctionFoo;
int main(){
glFunctionFoo = cast(extern(C) int function()) wglGetProcAddress("glFunctionFoo");
return 0;
}
Comment #1 by smjg — 2008-11-24T07:37:09Z
What exactly is the bug you're reporting?
- that that DStress test case seems to have been lost? If so, the product is wrongly set.
- that the code behaves incorrectly? If so, please be specific.
Comment #2 by clugdbug — 2010-01-19T02:47:17Z
This was an enhancement request, to allow extern(C) inside cast().
Comment #3 by razvan.nitu1305 — 2024-07-02T14:20:15Z
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.
Comment #4 by dkorpel — 2024-07-02T15:11:55Z
(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.
Comment #5 by razvan.nitu1305 — 2024-07-03T07:16:18Z
(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.
Comment #6 by robert.schadek — 2024-12-13T17:48:33Z