General guidelines for writing portable code
Here are some general guidelines for writing portable code.
-
Use functions supported by a major industry standard
(such as ABI, POSIX, X/Open).
-
When it is necessary to use functions
that are not part of a standard,
isolate the code in subroutines.
It will be easier to rewrite a subroutine when the code is ported
than to rewrite functionality that is spread throughout the code.
-
Study and resolve compiler and
lint(1)
warning messages.
These tools identify practices
that may cause porting problems.
-
Avoid hard-coded pathnames, files, directories,
or other system-dependent parameters within the code.
Use external files or environment variables to read
system-dependent data, instead of making hard-coded assumptions.
-
Apply internationalization techniques,
such as message catalogs and locale environment variables
to allow for world-wide usage.
Avoid non-portable, hard-coded language features
or assumptions about the system's character set.
-
Avoid usage of non-standard I/O devices.
-
Avoid assumptions about hardware-related parameters,
such as the byte length, byte order, word length,
or memory alignment.
-
Avoid assumptions about how the compiler operates internally; this
may vary from platform to platform.
Previous topic:
Determining compatibility issues
© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 27 April 2004