I always try to keep the platform specification out of the main code, doing it this way
platform.h:
#if BUILD_PLATFORM == WINDOWS_BUILD #include "windows_platform.h" #elif BUILD_PLATFORM == LINUX_BUILD #include "linux_platform.h" #else #error UNSUPPORTED PLATFORM #endif
someclass.c:
void SomeClass::SomeFunction() { system_related_type t;
Now in windows_platform.h and linux_platform.h you are typedef system_related_type for the native type and either #define platform_SystemCall as your own call, or create a small wrapper function if the argument set from one platform to another is too different.
If the system APIs for a specific task vary greatly between platforms, you may need to create your own version API that shares the difference. But for the most part, there are fairly direct comparisons between the various APIs on Windows and Linux.
Instead of relying on some specific #define compiler to select a platform, I #define BUILD_PLATFORM in a project file or makefile, since in any case they must be unique by platform.
Ashelly
source share