How do a write portable programs?

Dave Hammond daveh at marob.MASA.COM
Thu Sep 8 21:00:17 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? 

I suggest separating the code into application-level (code which should never
be concerned with the processor its running on) and system-level (device
i/o, subprocess control, signal handling, etc) routines.  Then develop a
standard interface between the 2 levels.  In this way you should only have to
heavily #ifdef the system-level routines.  For example, if echo is the
question, your application-level code might call a function Set_Echo_Off()
[a system-level routine] which should contain the #ifdefs relevant to echo
handling on various systems.

Dave Hammond
  UUCP: uunet!masa.com!{marob|dsix2}!daveh
DOMAIN: daveh at marob.masa.com
------------------------------------------------------------------------------



More information about the Comp.lang.c mailing list