.TH portability "" "" "Definition"
.PC
.PP
.B Portability
means that code can be recompiled and run under different
computing environments without modification.
Although true portability is an ideal that is difficult to
realize, you can take a number of practical steps to
ensure that your code is portable:
.RS
.IP \(bu 0.3i
Do not assume that an integer and a pointer have the same size.
Remember that undeclared functions are assumed to return an
.BR int .
If a function returns a pointer, declare it so.
.IP \(bu
Do not write routines that depend on a particular order of
code evaluation, particular byte ordering, or particular length
of data types.
.IP \(bu
Do not write routines that play tricks with a machine's \*(QLmagic
characters\*(QR; for example, writing a routine that depends on
a file's ending with \fB<ctrl-Z>\fR instead of \fBEOF\fR ensures
that that code can run only under operating systems that recognize
this magic character.
.IP \(bu
Always use manifest constants, such as \fBEOF\fR, and
make full use of \fB#define\fR statements.
.IP \(bu
Use header files to hold all machine-dependent declarations
and definitions.
.IP \(bu
Declare everything explicitly.
In particular, be sure to declare functions as
\fBvoid\fR if they do not return a value;
this avoids unforeseen problems with undefined return values.
.IP \(bu
Do not assume that integers and pointers have the same size or
even the same kind of structure.
Do not assume that pointers are
all the same or can point anywhere.
On the i8086, in SMALL model a pointer
to a function addresses relative to the code segment, whereas a
pointer to data addresses relative to the data segment.
On some machines, character pointers are of a different size or structure
than word pointers.
.IP \(bu
The constant NULL is defined as being different from any valid pointer.
Use it and nothing else for that purpose.
.IP \(bu
Keep test scripts, preferably at the function level.
That is, follow each function with an
.ID
	#ifdef TEST
.IE
section that will exercise that function.
Running these can rapidly isolate portability problems.
.IP \(bu
Place plenty of
.ID
	#assert
.IE
statements in your programs.
These can often pick up portability problems.
.RE
.SH "See Also"
.Xr "header files," header_fi
.Xr "pointer," pointer
.Xr "Programming COHERENT," programmi
.Xr "void" void
