Re: Clean way of generalizing CDECL

"Javier Arevalo" <[email protected]>
Newsgroups gmane.games.devel.general
Message-ID <[email protected]>
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



-------------------------------------------------------
This SF.Net email sponsored by Black Hat Briefings & Training.
Attend Black Hat Briefings & Training, Las Vegas July 24-29 - 
digital self defense, top technical experts, no vendor pitches, 
unmatched networking opportunities. Visit www.blackhat.com
_______________________________________________
Gamedevlists-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gamedevlists-general
Archives:
http://sourceforge.net/mailarchive/forum.php?forum_id=557
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.