Re: [GD-General] Clean way of generalizing CDECL
Brought to you by:
vexxed72
From: Javier A. <ja...@py...> - 2004-07-08 17:31:46
|
Ivan-Assen Ivanov wrote: > Ummm, ok, let's rephrase this: WHY do you need to explicitly specify > calling conventions in a cross-platform manner? It's not like you'd be > linking object files from one platform against the libs of the other. Most likely because you want to share many interfaces (header files) across platforms, therefore you want declarations to include "some" calling convention. Platform-specific configuration headers would #define the platform-specific details of that calling convention. It's not too different from the common technique used in Win32 DLL declarations: // DLLFunctions.h #ifdef DO_DLL_EXPORT #define DLL_FUNCTION __declspec(dllexport) #else #define DLL_FUNCTION __declspec(dllimport) #endif extern "C" DLL_FUNCTION int DLLFunction1(); extern "C" DLL_FUNCTION void DLLFunction2(); // DLLFunctions.cpp #define DO_DLL_EXPORT #include "DLLFunctions.h" // ...DLL functions implemented here // DLLUser.h #include "DLLFunctions.h" // ...Code here uses the DLL functions The original problem was that, since different platforms specify calling conventions in different places (some before the function, some after the parameters, etc), such a cross-platform call convention specifier may end up being too ugly. I don't think there are much better ways than suggested by Brian Sharon and Nick Trout. Techniques similar to Nick's are widely used in K&R-conforming portable libraries like ZLib: ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush)); The OF macro here is used to remove the parameters from declarations in K&R platforms. -- Javier Arevalo Pyro Studios |