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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

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

Compiler Differences<br />

A number of C compilers are available for various <strong>XENIX</strong> systems. The "Ri<strong>tc</strong>hie"<br />

compiler is available for PDP-11 systems. Available for the PDP-11 and most other<br />

<strong>XENIX</strong> systems is the Portable C Compiler.<br />

Signed/Unsigned char, Sign Extension<br />

The current state of the signed versus unsigned char problem is best described as<br />

unsatisfactory.<br />

The sign extension problem is a serious barrier to writing portable C, and the best<br />

solution at present is to write defensive code that does not rely on particular<br />

implementation features.<br />

Shift Operations<br />

The left shift operator >, when applied to an<br />

unsigned quantity, performs a logical shift operation. When applied to a signed quantity,<br />

the vacated bits may be filled with zero (logical shift) or with sign bits (arithmetic<br />

shift). The decision is implementation dependent, and code that uses knowledge of a<br />

particular implementation is nonportable.<br />

The PDP-11 compilers use arithmetic right shift. To avoid sign extension, you must<br />

shift and mask out the appropriate number of high order bits:<br />

char c;<br />

c = (c > > 3) & Ox1f;<br />

You can also avoid sign extension by using the divide operator:<br />

char c;<br />

c = c I 8;<br />

Identifier Length<br />

The use of long symbols and identifier names will cause portability problems with some<br />

compilers. To avoid these problems, a program should keep the following symbols as<br />

short as possible:<br />

• C preprocessor symbols<br />

• C local symbols<br />

• C external symbols<br />

A-7

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

Saved successfully!

Ooh no, something went wrong!