digitalmars.D.learn - extern(C) function literals for stubs
- Marco Leise (6/6) Jan 22 2014 Can I define them somehow? The use case is defining extern C
- bearophile (5/9) Jan 22 2014 Perhaps you want:
- Marco Leise (10/24) Jan 22 2014 Thanks, but I want it to be a function pointer so I can swap
- Marco Leise (17/31) Jan 22 2014 Got it now. By declaring the literal stub function in a
Can I define them somehow? The use case is defining extern C functions that contain code to load the real thing from a library. nothrow extern(C) void function(int) someFunc = ??? -- Marco
Jan 22 2014
Marco Leise:Can I define them somehow? The use case is defining extern C functions that contain code to load the real thing from a library. nothrow extern(C) void function(int) someFunc = ???Perhaps you want: extern(C) nothrow void someFunc(int someArg); Bye, bearophile
Jan 22 2014
Am Wed, 22 Jan 2014 17:52:03 +0000 schrieb "bearophile" <bearophileHUGS lycos.com>:Marco Leise:Thanks, but I want it to be a function pointer so I can swap it from within the function literal in the fashion of nothrow extern(C) void function(int) someFunc = (int arg) { someFunc = GetProcAddress("someFunc"); someFunc(arg); } -- MarcoCan I define them somehow? The use case is defining extern C functions that contain code to load the real thing from a library. nothrow extern(C) void function(int) someFunc = ???Perhaps you want: extern(C) nothrow void someFunc(int someArg); Bye, bearophile
Jan 22 2014
Am Wed, 22 Jan 2014 17:52:03 +0000 schrieb "bearophile" <bearophileHUGS lycos.com>:Marco Leise:Got it now. By declaring the literal stub function in a template instead I can use the normal function declaration syntax without introducing a new symbol at the definition site: { ... nothrow extern(C) void function(int) someFunc = &Stub!someFunc; ... } nothrow extern(C) auto Stub(alias func)(ParameterTypeTuple!func args) { debug printf("Loading %s...\n", func.stringof.ptr); return (func = &impl)(args); } -- MarcoCan I define them somehow? The use case is defining extern C functions that contain code to load the real thing from a library. nothrow extern(C) void function(int) someFunc = ???Perhaps you want: extern(C) nothrow void someFunc(int someArg); Bye, bearophile
Jan 22 2014