Porting Code

Porting to another platform Porting is the task of taking a program that works on one platform and making it work on another. This involves compiler changes, but also potentially adding new code to make up for missing features, or using new libraries available on the new platform, etc.!

Conditional Code

In porting we often have to add code that is included differently depending on the platform we are building on. A recommended approach is to place

#include "config.h"

at the top of C/C++ files, or include Fortran modules, etc. This can then include complex compile-time definitions.

When placing conditional code for different systems, name the conditional after the feature, not the platform. e.g., if building for a Cray, with a missing function srch() that is present on other platforms, then do:

#if !defined(HAS_DSRCH) ! Add dummy subroutine
subroutine d_srch
end
#endif

When building the code, configure can test to see if srch() exists or not. If it does exist then the variable HAS_SRCH can be defined as a compile option i.e. -DHAS_SRCH.

Supported By

File Browser Reference
Department FHERIS
University of Galway
HEA Logo