Sams Teach Yourself C in 21 Days

(singke) #1

APPENDIX D


Portability Issues


The term portabilityrefers to the ease with which a program’s source code can
be moved from one platform to another. Can the program you wrote for your
PC be compiled on a UNIX workstation? How about a Macintosh? One of the
major reasons people choose C as their programming language is its portability.
C is potentially one of the most portable programming languages.
Whypotentially? Most C compilers provide extensions,which are extra fea-
tures that can be very useful but that aren’t part of the C standard. If you try to
port to another platform a program that uses compiler extensions, you will
almost surely run into problems and have to recode parts of the program. If
you’re sure that your program will never be moved to another platform, you can
use your compiler’s extensions freely. However, if portability could be an issue,
you need to tread more carefully. This appendix outlines the issues you need to
consider.

The ANSI Standard

Portability doesn’t happen by accident. It occurs when you adhere to a set of
standards adhered to by other programmers and other compilers. For this rea-
son, it’s wise to choose a compiler that follows the standards for C program-
ming set by the American National Standards Institute (ANSI). The ANSI

47 448201x-APP D 8/13/02 11:17 AM Page 797

Free download pdf