Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!eng.ufl.edu!gnv.ifas.ufl.edu!sjs From: sjs@gnv.ifas.ufl.edu Newsgroups: comp.lang.c Subject: Re: Portability Issues Message-ID: <1991Apr24.115543.123@gnv.ifas.ufl.edu> Date: 24 Apr 91 16:55:43 GMT References: <2573@plx.UUCP> Lines: 50 In article <2573@plx.UUCP>, ming@plxsun.uucp (Lak-Ming Lam) writes: > I would like to develop program which can be portable to different system > (e.g. PC/MS-DOS, UNIX, Mac OS, etc.). I would like to have anyone of you > help me on the following issues: > > ... > o how to use one set of source code to support different systems > (using #if MSDOS etc. or some other ways) > ... I write in C for the PC and a VAX. I have a special include files whose contents are different on the PC and VAX, so I don't have to change the specifications in the source code. Example: #include "setups.h" where the contents on the PC would be for PC-specific setups, and the contents on the VAX would be for VAX-specific setups. At places where I have to use a machine-specific function (like keyboard handlers), I make a common name that I use throughout my code, and supply the machine-specific reference on the appropriate computer. For example: get_key_press (&key_value); The setups.h file on the PC may use a #define or a full function to take care of the keypress routine on the PC; the setups.h file on the VAX would define or use VAX-specific functions. I'd use #defines to assign words like EXIT or CANCEL to represent the key functions instead of passing back actual key values; this will make it easier to set things up in a switch block. The object is to create a maximum core of code that will work unchanged on more than one computer; supply computer-specific code in separate .h or .c files, which each residing on its respective machine. While this may result in some nested function calls to finally get to a computer-specific function, it will be much easier to manage. Unless speed is very critical, given the number of machines you are going to write your code for, I'd trade a few clock ticks for maximum common code. +---------------------------------------------+------------------------------+ | ~~~ Borco | "Time to wake up! | | / \ ~~~ at the Mountains of Madness | Time to rise!" | | / / \ | | | / / \ Bitnet: sjs@ifasgnv | - Silver Lady, | | / \ Internet: sjs@gnv.ifas.ufl.edu | Intergalactic Touring Band | +---------------------------------------------+------------------------------+