digitalmars.D.learn - Extern Keyword for Function Type
- Jeroen Bollen (11/11) Apr 15 2014 exten(C) {
- Jeroen Bollen (2/14) Apr 15 2014 Whoops, assume testFunction is defined as "void testFunction(...)"
- Dicebot (5/5) Apr 15 2014 C has no knowledge of D ABI so this can't work. If you just want
- Jeroen Bollen (3/8) Apr 15 2014 Hmm so the function passed should be declared as extern C but be
- Artur Skawina (6/19) Apr 15 2014 extern(C) {
- Dicebot (4/9) Apr 15 2014 Still does not allow you to actually call it from C side, so this
exten(C) { testFunction(int function(int)); } testFunction now requires an external function as parameter. It can't be called with a pointer to a D function. Logical Solution: extern(C) { testFunction(extern(D) int function(int)); // DOES NOT COMPILE } How do you fix this without moving it outside the global extern block?
Apr 15 2014
On Tuesday, 15 April 2014 at 20:15:42 UTC, Jeroen Bollen wrote:exten(C) { testFunction(int function(int)); } testFunction now requires an external function as parameter. It can't be called with a pointer to a D function. Logical Solution: extern(C) { testFunction(extern(D) int function(int)); // DOES NOT COMPILE } How do you fix this without moving it outside the global extern block?Whoops, assume testFunction is defined as "void testFunction(...)"
Apr 15 2014
C has no knowledge of D ABI so this can't work. If you just want to store D function pointer to later retrieve it and call from D code, you can as well store it as void* (or extern(C) with similar signature to preserve part of type) and cast upon interfacing.
Apr 15 2014
On Tuesday, 15 April 2014 at 20:19:36 UTC, Dicebot wrote:C has no knowledge of D ABI so this can't work. If you just want to store D function pointer to later retrieve it and call from D code, you can as well store it as void* (or extern(C) with similar signature to preserve part of type) and cast upon interfacing.Hmm so the function passed should be declared as extern C but be defined nonetheless? That makes sense.
Apr 15 2014
On 04/15/14 22:15, Jeroen Bollen wrote:exten(C) { testFunction(int function(int)); } testFunction now requires an external function as parameter. It can't be called with a pointer to a D function. Logical Solution: extern(C) { testFunction(extern(D) int function(int)); // DOES NOT COMPILE } How do you fix this without moving it outside the global extern block?extern(C) { extern (D) alias FP = int function(int); void testFunction(FP); } artur
Apr 15 2014
On Tuesday, 15 April 2014 at 22:32:10 UTC, Artur Skawina wrote:extern(C) { extern (D) alias FP = int function(int); void testFunction(FP); } arturStill does not allow you to actually call it from C side, so this is somewhat confusing. I'd really just go with void*
Apr 15 2014