Applications for more than one platform

 

Will your application run on more than one platform? Do you have a strategy to move to a different platform from the one that you use today? If the answer to either of these questions is yes, ensure that you code your programs for platform independence.

If you are using C, code in ANSI standard C. Use a standard C library function rather than an equivalent platform-specific function even if the platform-specific function is faster or more efficient. The exception is when efficiency in the code is paramount, when you should code for both situations using #ifdef. For example:

#ifdef _AIX
     AIX specific code
#else
     generic code
#endif

When you want to move the code to another platform, search the source for #ifdef with the platform specific identifiers, in this example _AIX, and add or change code as necessary.

Keep portable code in separate source files from the platform-specific code, and use a simple naming convention to split the categories.

 

Parent topic:

Application programming


fg10540_