Crossplatforming methods in C
Posted: Tue Nov 17, 2015 6:46 pm
By methods i mean ideologies, not code xD
I have been writing a General crossplatform library in C so that users can download the library, and make objects like threads out of the box. Basically abstracting 3 platform specific code into one, but i dont quite know what the better approach on doing so is. One one hand, i can write functions under if __linux__ or if __WIN32 || __64 , and then create a global function, could figure it out on runtime (Which technically it wont , it usually identifies itself by compile time) and do something like :
[code2=] #if __linux__
#define createThread(args) createThreadL(args)
#endif
#if __WIN32 || __WIN64
#define createThread(args) createThreadW(args)
#endif
[/code2]
or i can go about it another way, end each file with the operating system , like threading_linux.c threading_windows.c etc, and write a makefile which decides which ones i build. Also are there any other ideas/Tips on creating crossplatform code in C?
I have been writing a General crossplatform library in C so that users can download the library, and make objects like threads out of the box. Basically abstracting 3 platform specific code into one, but i dont quite know what the better approach on doing so is. One one hand, i can write functions under if __linux__ or if __WIN32 || __64 , and then create a global function, could figure it out on runtime (Which technically it wont , it usually identifies itself by compile time) and do something like :
[code2=] #if __linux__
#define createThread(args) createThreadL(args)
#endif
#if __WIN32 || __WIN64
#define createThread(args) createThreadW(args)
#endif
[/code2]
or i can go about it another way, end each file with the operating system , like threading_linux.c threading_windows.c etc, and write a makefile which decides which ones i build. Also are there any other ideas/Tips on creating crossplatform code in C?