Portability Issues
sjs at gnv.ifas.ufl.edu
sjs at gnv.ifas.ufl.edu
Thu Apr 25 02:55:43 AEST 1991
In article <2573 at plx.UUCP>, ming at 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 at ifasgnv | - Silver Lady, |
| / \ Internet: sjs at gnv.ifas.ufl.edu | Intergalactic Touring Band |
+---------------------------------------------+------------------------------+
More information about the Comp.lang.c
mailing list