CPP symbol usage and portability

Larry Wall lwall at sdcrdcf.UUCP
Tue Oct 23 04:25:14 AEST 1984


In article <915 at opus.UUCP> rcd at opus.UUCP (Dick Dunn) writes:
> > 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.

The trouble with this is that systems are multiplying out there faster than
we can keep track of them, and when your program shows up on a system that
you didn't know about, it will get only the default symbol values, which are
pretty sure to be incorrect.

I've been leaning more toward the feature by feature view lately.  You can
see the evolution of my thoughts in the Configure script I wrote for the
rn distribution kit.  Near the beginning it tries to figure out the system
type.  But does it use the system type for anything important?  Nope.  Only
to guess at a default answer here or there.  I try to determine the presence
or absence of each feature independently.

The reason for this is that there are more and more hybrid systems out
there.  What in the world is a Version 7 system with some Berkeley and some
USG extensions?  If I rely on the fact that it looks like a V7 system, rn
won't have any way to do a non-blocking read.  But one of those extensions
might have been FIONREAD, or O_NDELAY.  There's no way (currently) to find
out except by snooping around.

While I think Configure is a step in the right direction, it would be nice
if all the info was gathered into one spot so that snooping wasn't necessary.
The main problem that I see is: who is to say which features are to be, er,
featured.

What is needed is some way for each program to interrogate just those
features it's interested in, without having to worry about new feature
definitions cluttering up somebody or other's namespace.  The word
"interrogate" implies something a little more active than the current
include business, but not necessarily as active as calling getfoobars()s.
In fact, it could be done with with includes, if each feature definition
were "guarded" by a standard format symbol that you define before including
the feature list if you want to know about a given feature:

#ifdef GET_FOOBAR
#define FOOBAR		/* yes we foobar regularly */
#endif

#ifdef GET_BLURFL
#undef BLURFL		/* promised in the next release */
#endif

I agree, this is all very kludgey, but a given program would only have to
avoid colliding with new symbols of the form GET_*.

However it's done, whether at compile or run time, whether by shell script
or include file, the important thing is that a program only import the
names it is interested in.  The current CPP definitions do not have this, er,
feature.

Sorry, I'm not feeling very well either.

Larry Wall
{allegra,burdvax,cbosgd,hplabs,ihnp4,sdcsvax}!sdcrdcf!lwall



More information about the Comp.lang.c mailing list