Path: utzoo!attcan!uunet!husc6!bloom-beacon!tut.cis.ohio-state.edu!cwjcc!gatech!rutgers!cmcl2!lanl!unm-la!unmvax!nmtsun!warner@hydrovax.nmt.edu From: warner@hydrovax.nmt.edu (M. Warner Losh) Newsgroups: comp.lang.c Subject: How do a write portable programs? Message-ID: <1056@nmtsun.nmt.edu> Date: 4 Sep 88 23:53:11 GMT Sender: news@nmtsun.nmt.edu Organization: New Mexico Tech Hydrology Program Lines: 30 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@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...