CPP symbol usage and portability

Dick Dunn rcd at opus.UUCP
Fri Oct 19 18:04:42 AEST 1984


This took off from one of the CPP predefined symbol listings...
> 	#ifdef SYSTEM_X
> 		... Way to do it on sys X ...
> 	#else
> 		... Way to do it somewhere else ...
> 	#endif
> 
> Of course, this breaks when a program is spread to more that a few machines.

There's a way around that.  However, it's made messy by the fact that there
isn't an else-if construct for the preprocessor.  You build a sequence of
tests for each machine and a final branch, taken only when none of the
others are, either gives the default code or has a line of informative non-
code (to generate a compilation error) instructing you what you must fix:
	#ifdef SYS_X
		...code for X
	#else
	#ifdef SYS_Y
		...code for Y
	#else
		***Replace this line with code for mumble on your machine.
	#endif
	#endif

> What we really need here is something quite different: a set of #defines
> telling us what *features* are available on the target machine...

You can get some fair part of this if you have a common header file for
your code which has something like:
	#ifdef	SYS_X
	#define	FEATURE1
	#define FEATURE3
	#endif

	#ifdef	SYS_Y
	#define	FEATURE2
	#define	FEATURE3

A lot of this depends on how much you are worrying about portability / 
adaptability.
-- 
Dick Dunn	{hao,ucbvax,allegra}!nbires!rcd		(303)444-5710 x3086
   ...Lately it occurs to me what a long, strange trip it's been.



More information about the Comp.lang.c mailing list