How do a write portable programs?

M. Warner Losh warner at hydrovax.nmt.edu
Mon Sep 5 09:53:11 AEST 1988


write portable 'C' code.  Things like don't use 0, use NULL, but be
sure to always cast it.  Don't assume that a char is n bits long, but
you can assume that it will hold any character the machine you are on 
supports.  Side effects were also discussed.  Since all of that has been 
beat into the ground, I'd like to discuss the next level up.  Once you have 
done all the correct language bashing, what do you do about basic 
differences in environment?

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? 

That should be enough questions to start a lively disccussion.  I'm looking 
for how it is done in the real world and what the realtive strengths and 
weaknesses of the various methods are (#ifdefs are easy, but hard to read.  
More files are easier to read, but harder to maintain, etc) 

Cheers,
Warner Losh
--
warner%hydrovax at nmt.edu		...!unmvax!nmtsun!warner%hydrovax
..there was a *third* possibility we hadn't counted upon ...
My spelling and my views are my own.  Only the letters have been changed...



More information about the Comp.lang.c mailing list