09.06.2013 Views

Intel XENIX 286 Programmers Guide (86) - Tenox.tc

Intel XENIX 286 Programmers Guide (86) - Tenox.tc

Intel XENIX 286 Programmers Guide (86) - Tenox.tc

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

C Language Portability <strong>XENIX</strong> Programming<br />

Program Portability<br />

A program is portable if it can be compiled and run successfully on different machines<br />

without alteration. There are many ways to write portable programs. The first is to<br />

avoid using inherently nonportable language features. The second is to isolate any<br />

nonportable interactions with the environment, such as 1/0 to nonstandard devices. For<br />

example, programs should avoid hard-coding path names unless a path name is common<br />

to all systems (e.g., /e<strong>tc</strong>/passwd).<br />

Files required at compile time (i.e., include files) may also introduce nonportability if<br />

the path names are not the same on all machines. In some cases, include files<br />

containing machine parameters can be used to make the source code itself portable.<br />

Machine Hardwa re<br />

Differences in the hardware of the various target machines and differences in the<br />

corresponding C compilers cause the greatest number of portability problems. This<br />

section lists problems commonly encountered on <strong>XENIX</strong> systems.<br />

Byte Length<br />

By definition, the char data type in C must be large enough to hold as positive integers<br />

all members of a machine's character set. For the machines described in this appendix,<br />

the char size is exactly an 8-bit byte.<br />

Word Length<br />

In C, the size of the basic data types for a given implementation are not formally<br />

defined. Thus they often follow the most natural size for the underlying machine. It is<br />

safe to assume that short is no longer than long. Beyond that no assumptions are<br />

portable. For example, on some machines short is the same length as int, whereas on<br />

others long is the same length as int.<br />

Programs that need to know the size of a particular data type should avoid hard-coded<br />

constants where possible. Such information can usually be written in a fairly portable<br />

way. For example, the maximum positive integer (on a two's complement machine) can<br />

be obtained with<br />

A-2<br />

#defi ne MAXPOS ((int) (((unsigned)-1) >> 1))

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!