Date: Sun, 20 Oct 2002 14:34:16 -0600 (MDT) From: "M. Warner Losh" <imp@bsdimp.com> To: freebsd-standards@FreeBSD.ORG, freebsd-hackers@FreeBSD.ORG Subject: Re: Problem detecting POSIX symbolic constants Message-ID: <20021020.143416.109047247.imp@bsdimp.com> In-Reply-To: <20021020204920.C8767@chiark.greenend.org.uk> References: <20021016121455.A3711@chiark.greenend.org.uk> <20021020.134409.73085448.imp@bsdimp.com> <20021020204920.C8767@chiark.greenend.org.uk>
next in thread | previous in thread | raw e-mail | index | archive | help
In message: <20021020204920.C8767@chiark.greenend.org.uk>
Tony Finch <dot@dotat.at> writes:
: On Sun, Oct 20, 2002 at 01:44:09PM -0600, M. Warner Losh wrote:
: > Tony Finch <dot@dotat.at> writes:
: > : On Sat, Oct 12, 2002 at 01:20:03PM -0700, Terry Lambert wrote:
: > : >
: > : > #if _DEFINED_SUPPORTED && defined(SOMETHING)
: > :
: > : That's a syntax error in pre-ANSI preprocessors (unless defined() is
: > : #defined), which won't be bypassed by evaluation shortcutting since
: > : evaluation happens after parsing.
: >
: > Actaully, it is only a syntax error on some really really really old
: > cpp. The sun cpp on SunOS 4.x, for example, wasn't ANSI, but did grok
: > the above construct.
:
: Yes, the C manual in -CURRENT which sates from 1986 documents defined().
: I haven't found any versions of the manual between 1975 (h0h0 C) and
: then, and I don't have a copy of K&R 1 :-/
I can verify first hand that SunOS 3.5 (and I think 3.2) behaved the
same way as SunOS 4.1.3 did.
My copy of K&R 1 is silent on this issue (well, as I recall, I can't
find my K&R1 at the moment), which means defined isn't likely to be
there. My copy of the Bell Laboratories Technical Journal October
1984 (Vol 63 No.8 Part 2) says, in "The Evolution of C -- Past and
Future" by L. Rosler, section 5.9 Compiler Control Lines:
The conditional-compile facility (Ref 2. Sect 12.3) has been
enhanced in two ways.
To facilitate selection of one among a set of choices, any
number of control lines of the form
#elif constant-expression
may now appear on any line between a #if line and its closing
#endif (or #else if present).
The new pseudofunction defined(identifier) may be used in the
constant-expression part of a #if or #elif control line, with
value 1 if the identifier is currently defined in the
preprocessor, and 0 otherwise. Thus #ifdef identifier is
equivalent to #if defined(identifier) and #ifndef identifier
is equivalent to #if !defined(identifier). The older forms
will be retained for compatibility, as they are deeply
entrenched in existing code. But, as they are superfluous,
equivalents to #ifdef will not be provided for the new
construction #elif.
Ref 2 looks to be K&R1:
2. B. W. Kernighan and D. M. Ritchie, The C Programming
Language, Englewood Cliffs, NJ.: Prentice Hall, 1978.
So it looks like it was added just after K&R1, but early enough that
4.2BSD had it (and maybe earlier), which would explain why SunOS groks
it. 1984 definitely pre-dates the standard (and in fact this same
article goes on to describe varadic functions with a syntax that is
different than what was finally adapoted).
Warner
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-standards" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20021020.143416.109047247.imp>
