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:
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.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 instead up to twenty */ stack, stack, stack, stack, \ stack, stack, stack, stack, \ stack, stack, stack, stack, \ stack, stack, stack, stack, \ stack, stack, stack, stack \ // 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.
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.