#define DLL_EXPORT __declspec(dllexport) __cdecl // gcc -shared -o simple-native.dll simple.c static char do0(int type) { return 'a'; } static const char * const buf1 = "lalali"; static const char * const do1(int type) { return buf1; } static float do2(int type, float f1, float f2) { return f1 * f2; } static double do3(int type, double d1, double d2) { return d1 * d2; } struct Foo { int f1; short f2; double f3; }; static double do4(int type, struct Foo foo) { return foo.f1 * foo.f2 * foo.f3; } static struct Foo do5(int type, struct Foo foo1, struct Foo foo2) { foo1.f1 *= foo2.f1; foo1.f2 *= foo2.f2; foo1.f3 *= foo2.f3; return foo1; } static const char * const do6(int type, struct Foo foo1) { return buf1; } DLL_EXPORT void forward(int type) { void (*fct)(); switch(type) { case 0: fct = (void (*)()) &do0; break; case 1: fct = (void (*)()) &do1; break; case 2: fct = (void (*)()) &do2; break; case 3: fct = (void (*)()) &do3; break; case 4: fct = (void (*)()) &do4; break; case 5: fct = (void (*)()) &do5; break; case 6: fct = (void (*)()) &do6; break; } void* args = __builtin_apply_args(); __builtin_return( __builtin_apply( fct, args, 10 * sizeof(int) )); }