export defines

export defines

Discuss the source code and development of Spring Engine in general from a technical point of view. Patches go here too.

Moderator: Moderators

Post Reply
User avatar
hoijui
Former Engine Dev
Posts: 4344
Joined: 22 Sep 2007, 09:51

export defines

Post by hoijui »

In the C AI branch, I have a file exportdefines.h:
http://pastebin.com/m1561a96a

It is used in unitsync and the C AI interface, and it allows one to write lines that before looked this:

Code: Select all

DLL_EXPORT void __stdcall UnInit()
to look like this:

Code: Select all

Export(void) UnInit()
other possibilities:

Code: Select all

SHARED_EXPORT void CALLING_CONV UnInit() // same effect as above
void CALLING_CONV UnInit()               // use __stdcall calling convention
SHARED_EXPORT void UnInit()              // export the function (will most likely not be used in spring)
These things are nothing new or fancy, but Export() makes the code look cleaner. SHARED_EXPORT is a better fitting name then DLL_EXPORT, as it is portable. CALLING_CONV instead of __sdtcall directly is not really needed, but does not hurt, and allows for easy experiments. For example, one could easily test how an other calling convention relates to speed (when using AIs eg).

I am using this file since some months already, and it works well (tested on windows with mingw and on linux with mingw, gcc and the intel compiler).

Any objections against integrating this into trunk?

I though on one of the following locations:
rts/System/exportdefines.h
rts/System/ExportDefines.h
Tobi
Spring Developer
Posts: 4598
Joined: 01 Jun 2005, 11:36

Re: export defines

Post by Tobi »

hoijui wrote:

Code: Select all

DLL_EXPORT void __stdcall UnInit()
to look like this:

Code: Select all

Export(void) UnInit()
I do like this, though it should be EXPORT IMHO to make it clear it's a #define :-)

The other solution, with CALLING_CONV, looks a bit too convoluted to me. (Makes for very long function headers...)
User avatar
hoijui
Former Engine Dev
Posts: 4344
Joined: 22 Sep 2007, 09:51

Re: export defines

Post by hoijui »

yeah true, EXPORT() is better.

what about the file name? exportdefines.h or ExportDefines.h?
i saw some files beeing al lower (eg aikey.h or aibase.h) and this somehow fits... cause it is only a header.
plus: it is also fully C compatible, and can therefore be used by all AI Interfaces eg.
Post Reply

Return to “Engine”