digitalmars.D - Can I typedef pointer to extern (C) function?
- Rick Mann (1/1) Jan 26 2007 I'm having trouble posting. If this succeeds, I'll post the rest in a fo...
- Rick Mann (27/28) Jan 26 2007 So, I have the following example (gdc on Mac OS X, DMD 1.00-based):
- Rick Mann (3/41) Jan 26 2007 Sorry, forgot the rest of the question. It seems to dislike the "extern...
- Mike Parker (5/38) Jan 27 2007 Switch up the 'alias' and extern(C) statements:
- Mike Parker (2/2) Jan 27 2007 Oh, and just to be pedantic, typedef and alias are not the same. The
- Rick Mann (4/8) Jan 27 2007 I did eventually discover that, and now I'm just getting Bus errors when...
I'm having trouble posting. If this succeeds, I'll post the rest in a follow-on.
Jan 26 2007
Rick Mann Wrote:I'm having trouble posting. If this succeeds, I'll post the rest in a follow-on.So, I have the following example (gdc on Mac OS X, DMD 1.00-based): alias extern (C) uint function() EventHandlerProcPtr; extern (C) uint func1() { return 0; } uint func2() { return 0; } void main() { EventHandlerProcPtr p = &func1; EventHandlerProcPtr q = &func2; } /* Compiling with gdc generates the following errors: $ gdc callbacktest.d callbacktest.d:23: Error: cannot implicitly convert expression (& func1) of type uint(C *)() to uint(*)() $ */
Jan 26 2007
Rick Mann Wrote:Rick Mann Wrote:Sorry, forgot the rest of the question. It seems to dislike the "extern (C)" in my target function declaration, but I get bus errors if I omit it (as one might expect). Any suggestions would be most welcome.I'm having trouble posting. If this succeeds, I'll post the rest in a follow-on.So, I have the following example (gdc on Mac OS X, DMD 1.00-based):alias extern (C) uint function() EventHandlerProcPtr; extern (C) uint func1() { return 0; } uint func2() { return 0; } void main() { EventHandlerProcPtr p = &func1; EventHandlerProcPtr q = &func2; } /* Compiling with gdc generates the following errors: $ gdc callbacktest.d callbacktest.d:23: Error: cannot implicitly convert expression (& func1) of type uint(C *)() to uint(*)() $ */
Jan 26 2007
Rick Mann wrote:Rick Mann Wrote:Switch up the 'alias' and extern(C) statements: extern(C) alias uint function() EventHandlerProcPtr;Rick Mann Wrote:Sorry, forgot the rest of the question. It seems to dislike the "extern (C)" in my target function declaration, but I get bus errors if I omit it (as one might expect). Any suggestions would be most welcome.I'm having trouble posting. If this succeeds, I'll post the rest in a follow-on.So, I have the following example (gdc on Mac OS X, DMD 1.00-based):Also, as written, func2 is not extern(C), only func1 is. That's likely why you only saw the error for func1.extern (C) uint func1() { return 0; } uint func2() { return 0; } void main() { EventHandlerProcPtr p = &func1; EventHandlerProcPtr q = &func2; }
Jan 27 2007
Oh, and just to be pedantic, typedef and alias are not the same. The subject line says one and the code uses the other.
Jan 27 2007
Mike Parker Wrote:Oh, and just to be pedantic, typedef and alias are not the same. The subject line says one and the code uses the other.Yeah; sorry about that. I had trouble posting it the first time (kept getting "Fail to post message"), and when I tried again later I had been experimenting, so I think my example got changed.Switch up the 'alias' and extern(C) statements: extern(C) alias uint function() EventHandlerProcPtr;I did eventually discover that, and now I'm just getting Bus errors when my callback happens. My actual code is using Mac OS X's Carbon API, where it calls you back for events. I'm not sure what's causing the problem at this point, but I'll keep poking at it. Thanks!
Jan 27 2007