How do a write portable programs?

Wietse Venema wietse at wzv.UUCP
Fri Sep 9 07:54:05 AEST 1988


In article <1056 at nmtsun.nmt.edu> warner at hydrovax.nmt.edu (M. Warner Losh) writes:
>How do I write program that are easily protable when I HAVE TO use the
>system calls (be they setitimer() or lib$init_timer() or int21()...).  Is
>there a good and easy way that I can write my programs so that most of the
>code never has to be touched when I port?  What is the best way of handling
>system dependent routines?  Assume the whole world is UNIX and then write
>UNIX system call emulation on those that aren't?  Or should I write
>routines that will do some functions (say turn off echo, but that is a bad
>example) regardless of how that function gets done.  Should I use zillions
>of #ifdefs everywhere? or should there be files that contain source code
>for only one system? 

You might take a look at `software tools' by Kernighan and Plauger.
It's a little old (1978) and uses a different language (Ratfor), but
provides good examples of encapsulating system-dependent code in a small
collection of interface routines.  I must admit that this portable
interface is patterned after the standard UNIX programming interface.

These ideas have been elaborated by some people (at Berkeley?) and
resulted in VOS, a virtual operating system. Basically, it is a thin
layer of routines that map requests to system calls of the local OS.
Porting software then becomes a matter of writing an appropriate VOS
implementation.

			Wietse
-- 
work:	wswietse at eutrc3.uucp	| Eindhoven University of Technology
ditto:	wswietse at heitue5.bitnet	| Mathematics and Computing Science
home:	wietse at wzv.uucp		| 5600 MB Eindhoven, The Netherlands



More information about the Comp.lang.c mailing list