[comp.lang.c] Horton, "Portable C Software"

mcdaniel@amara.uucp (Tim McDaniel) (04/10/90)

Mark Horton, "Portable C Software", Prentice-Hall, Englewood Cliffs,
NJ, 1990.  ISBN 0-13-868050-7.  379 pages.  $32.80 at a local
bookstore.

Picoreview: Highly recommended.  With Koenig's "C Traps and Pitfalls",
likely to become a classic text for serious C programmers.

Nanoreview: Lots of lineage/historical info on UNIX variations.  Good
information on general programming practice.  Excellent reference
section describing library functions, variables, include files, et
cetera.  Fine Appendices.

What can I say?  The book fully lives up to its title.

Part I asks "why write portable software" and describes the history of
C and UNIX.  Part II contains suggestions for writing portable
software: not just designing or porting existing programs, but also
considering variations in user interfaces and network protocol
designs.  Part III lists considerations in a portable program:
hardware, C language, and operating system dependencies.  Part IV is a
splendid reference on the portability of C library and operating
system calls, include files, predefined variables, and (UNIX) user
commands.  (For instance, every function that is "standard" in one way
or another is listed, along with portability concerns (it hasn't been
around long, it's in a big standard so it should become more common,
differences in semantics among systems, differences in arguments
passed among systems, et cetera).)  The appendices generally describe
systems and standards; these are almost worth the price of admission
on their own.  There's a table of what the ANSI C standard leaves
undefined/implementation-defined/....  There's the source for ATT
getopt function.  There are quick 1-line portability references for
all the functions listed more fully earlier.

There are few glitches: recommending calloc "when the area to be
allocated must be initialized to all zeros" is the worst one I saw.
(For the uninitiated, the problem lies in the meaning of "zero".
calloc initializes BYTES to zero, so strings and integral variables
are covered; floating-point zeros need not be composed of bytes
containing zeros.  Malloc is certainly in the ANSI C standard; is
calloc?  I dunno;  ANSI is late publishing the C standard.)

Horton is rather careful to differentiate UNIX and C---for example,
portability to MS/DOS is considered throughout.  However, there may
need to be a bit more attention to this issue: for instance, read is
recommended as a faster (!) alternative to fread "at a minor decrease
in portability" (!).

The include file discussion ought to list the functions and variables
declared, not just macros and such.  In general, there should be more
discussion and indexing of the meaning and use of each identifier.
("Get password", for instance, is the only description of "getpass",
and is misleading.)  That way, a naive programmer who knows *what*
they want to do but don't know the exact function name can select a
more portable call.

Otherwise, my comments were largely "true, but it's a little better to ...".

--
Tim McDaniel
Applied Dynamics International, Ann Arbor, MI
Internet: mcdaniel%amara.uucp@mailgw.cc.umich.edu
UUCP: {uunet,sharkey}!amara!mcdaniel