Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.2 9/17/84; site opus.UUCP
Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!godot!harvard!seismo!hao!cires!nbires!opus!rcd
From: rcd@opus.UUCP (Dick Dunn)
Newsgroups: net.lang.c
Subject: CPP symbol usage and portability
Message-ID: <915@opus.UUCP>
Date: Fri, 19-Oct-84 04:04:42 EDT
Article-I.D.: opus.915
Posted: Fri Oct 19 04:04:42 1984
Date-Received: Sun, 21-Oct-84 14:45:29 EDT
References: <5056@root44.UUCP> <6087@mcvax.UUCP>
Organization: NBI,Inc, Boulder CO
Lines: 43

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.