|
|
coherent
portability Technical Information portability
Portability means that code can be recompiled and run under dif-
ferent 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:
11.
Do not assume that an integer and a pointer have the same
size. Remember that undeclared functions are assumed to
return an int. If a function returns a pointer, declare it
so.
22.
Do not write routines that depend on a particular order of
code evaluation, particular byte ordering, or particular
length of data types.
33.
Do not write routines that play tricks with a machine's
``magic characters''; for example, writing a routine that
depends on a file's ending with <ccttrrll-ZZ> instead of EEOOFF en-
sures that that code can run only under operating systems
that recognize this magic character.
44.
Always use manifest constants, such as EEOOFF, and make full
use of #ddeeffiinnee statements.
55.
Use header files to hold all machine-dependent declarations
and definitions.
66.
Declare everything explicitly. In particular, be sure to
declare functions as vvooiidd if they do not return a value;
this avoids unforeseen problems with undefined return
values.
77.
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 ad-
dresses relative to the data segment. On some machines,
character pointers are of a different size or structure than
word pointers.
88.
The constant NULL is defined as being different from any
valid pointer. Use it and nothing else for that purpose.
COHERENT Lexicon Page 1
portability Technical Information portability
***** See Also *****
header file, pointer, technical information, void
COHERENT Lexicon Page 2
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.