jump to navigation

How to create multiplatform software using C/C++? May 23, 2008

Posted by fahdk in Computing.
Tags: , , , , ,
4 comments

I am sure there would be many ways and approaches to creating multiplatform software that people have used over the years. Here I humbly present three basic points about an approach that I have found to be useful. Readers are encouraged to voice their opinions in the Comments section.

Point 1: Start off with platform independent data types.

Basically create a header file that defines your own custom data types and maps them to the fundamental data types available on the system. Have separate sections for each platform and it is good to repeat your definition for each data type separately for each platform so that changing things on a particular platform would be easier later. Sample code follows…

#if defined (LINUX && __X86__)

typedef long long myint64;

#elif defined (LINUX && __X64__)

typedef long myint64;

#elif defined (SOLARIS && __X86__)

Point 2: Create a platform abstraction library.

Something like the Apache Portable Runtime or the Netscape Portable Runtime but instead of using these or developing something like these, you can develop your own small little static abstraction library and add only those abstractions to it that you need for your project. As a side note, remember that the Pthreads library is available on the windows platform as well.

Point 3: Create your software utilizing the platform independent data types and platform abstraction library.

Make sure you never use system defined types in your application nor do you use any platform specific system call directly.

This approach should help you create reliable and maintainable multiplatform software.

Thanks.