Thread: Re: [GD-General] Clean way of generalizing CDECL
Brought to you by:
vexxed72
From: brian s. <pud...@po...> - 2004-07-06 23:40:47
|
I never came up with anything better than CDECL_PRE and CDECL_POST but that solution sure won't win any beauty contests :). What did the MingW people do for this? All of the Windows API functions are stdcall, and surely they didn't modify every Windows header to change the declarations. They must be able parse them as-is. Maybe there's a solution to be found there? --brian > I'd like to be able specify CDECL in a cross-platform manner. On most > x86 compilers there's just the __cdecl keywod: > > void __cdecl foo( int x, int y, int z ); > > GCC, of course, does it completely differently: > > void foo( int x, int y, int z ) __attribute((cdecl)); > > So a simple #define won't work. Now, you can do a kind of convoluted > thing using a define, but damn, it's REAL ugly. > > Is there a cleaner way of doing this? > |
From: Nick T. <ni...@ro...> - 2004-07-07 20:11:32
|
> -----Original Message----- > From: gam...@li... > [mailto:gam...@li...] On Behalf Of > Brian Hook > Sent: Tuesday, July 06, 2004 3:11 PM > To: gam...@li... > Subject: [GD-General] Clean way of generalizing CDECL >=20 > I'd like to be able specify CDECL in a cross-platform manner. On most > x86 compilers there's just the __cdecl keywod: >=20 > void __cdecl foo( int x, int y, int z ); >=20 > GCC, of course, does it completely differently: >=20 > void foo( int x, int y, int z ) __attribute((cdecl)); >=20 > So a simple #define won't work. Now, you can do a kind of convoluted > thing using a define, but damn, it's REAL ugly. Why not: #define foo(T,N, ...) T __cdecl N ( __VA_ARGS__ ) foo (int, blah, int a, int b) // declaration or #define foo2(T,N,A) T __cdecl N A=20 foo2 (int, blah, (int a, int b)) // declaration Nick |
From: Brian H. <ho...@bo...> - 2004-07-07 21:53:55
|
> Why not: > > #define foo(T,N, ...) T __cdecl N ( __VA_ARGS__ ) __VA_ARGS__ is C99, which isn't widely supported yet. > #define foo2(T,N,A) T __cdecl N A > > foo2 (int, blah, (int a, int b)) // declaration Nick, LOOK at that line for a second, and then ask yourself why I wouldn't want to write something like that =3D) Brian |
From: Nick T. <ni...@ro...> - 2004-07-07 22:42:58
|
> > foo2 (int, blah, (int a, int b)) // declaration >=20 > Nick, LOOK at that line for a second, and then ask yourself why I > wouldn't want to write something like that =3D) I think that looks like an excellent Lisp example. :) It works doesn't it! I'd rather see that than loads of #ifdefs (e.g. see GLUT headers) And you can easily add new platforms which also don't comply later.=20 Nick |
From: Stefan B. <Ste...@di...> - 2004-07-08 11:28:51
|
Why do you want to generalize it? Isn't cdecl something very win32-specific anyway? /Stefan -----Original Message----- From: gam...@li... [mailto:gam...@li...] On Behalf Of Brian Hook Sent: 07 July 2004 00:11 To: gam...@li... Subject: [GD-General] Clean way of generalizing CDECL I'd like to be able specify CDECL in a cross-platform manner. On most=20 x86 compilers there's just the __cdecl keywod: void __cdecl foo( int x, int y, int z ); GCC, of course, does it completely differently: void foo( int x, int y, int z ) __attribute((cdecl)); So a simple #define won't work. Now, you can do a kind of convoluted=20 thing using a define, but damn, it's REAL ugly. Is there a cleaner way of doing this? ------------------------------------------------------- This SF.Net email sponsored by Black Hat Briefings & Training. Attend Black Hat Briefings & Training, Las Vegas July 24-29 -=20 digital self defense, top technical experts, no vendor pitches,=20 unmatched networking opportunities. Visit www.blackhat.com _______________________________________________ Gamedevlists-general mailing list Gam...@li... https://lists.sourceforge.net/lists/listinfo/gamedevlists-general Archives: http://sourceforge.net/mailarchive/forum.php?forum_idU7 |
From: Brian H. <ho...@bo...> - 2004-07-08 13:26:54
|
> Why do you want to generalize it? Isn't cdecl something very win32- > specific anyway? Yes and no. cdecl, fastcall, stdcall, etc. are x86 specific (not just Win32), but many platforms still have multiple calling conventions (e.g. MacOS on the 68K had at least three if I remember: pascal, OS, and something else). So you still need to be able to explicitly specify calling conventions somehow in a vaguely cross-platform manner. Brian |
From: Ivan-Assen I. <as...@ha...> - 2004-07-08 15:09:15
|
> Yes and no. cdecl, fastcall, stdcall, etc. are x86 specific > (not just Win32), but many platforms still have multiple > calling conventions (e.g. MacOS on the 68K had at least three > if I remember: pascal, OS, and something else). So you still > need to be able to explicitly specify calling conventions > somehow in a vaguely cross-platform manner. 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. |
From: Brian H. <ho...@bo...> - 2004-07-08 16:30:59
|
> Ummm, ok, let's rephrase this: WHY do you need to explicitly > specify calling conventions in a cross-platform manner? I don't, but I need to be able to have them specified on one platform and then not have them fail when compiled on another platform. Brian |
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 |
From: Brian H. <ho...@bo...> - 2004-07-08 18:07:55
|
> Most likely because you want to share many interfaces (header > files) across platforms, therefore you want declarations to include > "some" calling convention. Exactly. And it's necessary to specify calling conventions so that your library compiled with one convention is compatible with someone else's application that may have been built with __fastcall. PoshLib (www.poshlib.org) tries to solve most of these problems cleanly and portably, which is why I'm asking about this. I'm glad to find out that __attribute__((cdecl)) seems to be prefix or suffix friendly. With POSH you do: void POSH_CDECL foo( int x ); or, if you ant DLL export to work magically as well: POSH_PUBLIC_API( void ) POSH_CDECL foo( int x ); Brian |
From: Jeremy V. <mad...@gm...> - 2004-07-08 19:49:06
|
Hey guys, The way I would choose, which is easy on the eyes, is to always define __cdecl functions with both, and then have defines that eliminate one syntax or the other depending on the platform. Such as: #ifdef WIN32 # define __attribute(x) #else # define __cdecl #endif int __cdecl myFunction(double whatever) __attribute((cdecl)); Actually, this is the same as Brian's CDECL_PRE and CDECL_POST - so I should probably just stick to lurking :p |
From: Brian H. <ho...@bo...> - 2004-08-03 00:19:03
|
I'm trying to find some tiles to prototype a simple (2D) isometric engine, and unlike sprites or 3D models it seems that there's a tough time finding iso (2:1, diamond map) art work out there. Anyone know of a good resource (cheap commercial or free) suitable for this? Thanks, Brian |
From: Peter B. <fla...@gm...> - 2004-08-03 17:33:13
|
there's falcon's eye the isometric nethack (not sure what the 'nethack public license' is tho'). Shots: http://www.hut.fi/~jtpelto2/nhfeatures.html dowload: http://falconseye.sourceforge.net/ On Mon, 2 Aug 2004 20:18:53 -0400, Brian Hook <ho...@bo...> wrote: > I'm trying to find some tiles to prototype a simple (2D) isometric > engine, and unlike sprites or 3D models it seems that there's a tough > time finding iso (2:1, diamond map) art work out there. > > Anyone know of a good resource (cheap commercial or free) suitable for > this? > > Thanks, > > Brian > > ------------------------------------------------------- > This SF.Net email is sponsored by OSTG. Have you noticed the changes on > Linux.com, ITManagersJournal and NewsForge in the past few weeks? Now, > one more big change to announce. We are now OSTG- Open Source Technology > Group. Come see the changes on the new OSTG site. www.ostg.com > _______________________________________________ > Gamedevlists-general mailing list > Gam...@li... > https://lists.sourceforge.net/lists/listinfo/gamedevlists-general > Archives: > http://sourceforge.net/mailarchive/forum.php?forum_idU7 > |