ross wrote:
Well primarily platform.h would have in some things that already exist in the code.
For instance macosx/platform.h would likely have
implementations of wcslen(), stricmp() and so forth that are not available on the OS X platform. Obviously the windows/platform.h would not need to have these and would probably just include <windows.h>. Linux also has the wcs* funcs (I think) and would therefore just #include <wchar.h>.
Other functions which are endian centric could also be moved into the platform.h isolating them from the code.
I know it seems like an unnecessary amount of work but I really do dislike conditional compilation
I would also like to reduce the amount of conditional compilation, but it doesn't seem important to move all of it into one file (i.e. platform.h). In some cases, I think this could make the code organization more difficult to understand.
For example, we have endian conversions being performed in CDbPackedVars::UnpackBuffer(). I wouldn't want to move the unpack buffer function into platform.h/cpp or have it be a separate included file that is included by platform.h. For the simplest organization, the buffer-unpacking code belongs in that class and in that file.
(My apologies, if I've misunderstood you and you weren't proposing to isolate the platform-specific code this way.)
To make the above function easier to maintain, I think we need a few macros that give endian-influenced values consistent byte orders for storage. And we replace, the #ifdef _sgi blocks with the macros. Elsewhere, like in platform.h/ports.h, the macro is defined to do different things on different platforms. So code like this:
#ifdef __sgi
LittleToBig(&wVarNameSize);
#endif
...could instead be written like:
wVarNameSize = S2L16(wVarNameSize);
"
N2L16"
= Convert a 16-bit integer from storage byte order to local byte order, which might be the same, in which case a variable would just be assigned to itself, and probably compile out.
It occurs to me that you might have been proposing about the same thing as me. My basic point is that it is not my goal to move all conditional compilation into platform.h, when code should instead be grouped by its functionality.
Side note: There is very little that we use from windows.h and its vast number of declarations tends to cause problems. So if I have to use it, I include it from a .CPP and whatever functionality it uses will be exposed by functions in that module. Example is SysTimer.h/cpp in the "
BackEndLib"
project.
-Erik
____________________________
The Godkiller - Chapter 1 available now on Steam. It's a DROD-like puzzle adventure game.
dev journals |
twitch stream |
youtube archive (NSFW)