Path: utzoo!attcan!uunet!lll-winken!lll-tis!ames!nrl-cmf!cmcl2!phri!marob!daveh From: daveh@marob.MASA.COM (Dave Hammond) Newsgroups: comp.lang.c Subject: Re: How do a write portable programs? Message-ID: <404@marob.MASA.COM> Date: 8 Sep 88 11:00:17 GMT References: <1056@nmtsun.nmt.edu> Reply-To: daveh@marob.masa.com (Dave Hammond) Organization: ESCC New York City Lines: 24 In article <1056@nmtsun.nmt.edu> warner@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@marob.masa.com ------------------------------------------------------------------------------