Oi!
I've made my own programming language using C++ as the base for it (All code for the interpreter is in C++ and the Dev-API is in C++).
Now for my next version I've made a Dynamic Linker for it written in C++, which will let my language to open up Shared libraries like *.so and *.dll files.
Here's my problem. Since I can't predict before hand how the function pointer should be since my language is compiled at run time. So my Dynamic Linker has to have a "unified" pointer. Well I have one for each return type. The argument list is the tricky one. And I could solve this in GCC by turning the pointer to this:
Code:
typedef long ArgType;
#define ARGLIST \ /* Sets twenty ArgType after each other like an argument list with up to twenty arguments */
ArgType, ArgType, ArgType, ArgType, \
ArgType, ArgType, ArgType, ArgType, \
ArgType, ArgType, ArgType, ArgType, \
ArgType, ArgType, ArgType, ArgType, \
ArgType, ArgType, ArgType, ArgType \
#define ARGSTACK(stack) \ /* The same as before but with stack[0] instead up to twenty */
stack[0], stack[1], stack[2], stack[3], \
stack[4], stack[5], stack[6], stack[7], \
stack[8], stack[9], stack[10], stack[11], \
stack[12], stack[13], stack[14], stack[15], \
stack[16], stack[17], stack[18], stack[19] \
// More code
<type> (*pointerParsed)(ARGLIST) = (<type> (*)(ARGLIST) pointerToFunctionInMemory;
pointerParsed(ARGSTACK(argStack)); // Call the function, argStack is an array of twenty with long values for arguments.
This works for GCC. But in VC++ I get a problem. The function pointerParsed points at is called (for instance I opened kernel32.dll and used Sleep(5000) and it sleept for 5 second) but when it returns everything crashes down. And I get an exception from Visual Studio which tells me that this happen when I call a function with a pointer that has a different calling convention. I need a solution for that. But I'm a Linux developer and not that familiar with VC++. I haven't been capable of coming up with anything that fixes this.
I know this is not part of standard C++ or anything like that. I got criticism when asking for help in an IRC channel telling me I was a moron and idiot because they thought it was broken. Ruby's Dynamic Linker (written in C) uses the same thing as me. Though I couldn't find how they solved it with VC++. Or maybe it can't be compiled by VC++ simply.