[net.unix] Standardized predefined CPP symbols, down with folklore

geo@watdcsu.UUCP (Geo Swan) (07/07/84)

I agree with the need for standards.
Further, these standards should be properly documented.
I learned that cpp automatically sharp defined "unix",
when I tried to declare a variable named "unix".  (Try it sometime.)
When I posted a local gripe, a number of people kindly
explained this convention to me  (In fact, prior to posting
my gripe, I figured the convention out through trial and error.)

This is folklore.

None of my informants knew if and where this feature was documented.
Undocumented features like this are booby-traps.

dmcanzi@watmath.UUCP (David Canzi) (07/07/84)

In addition to documenting these predefined symbols, the symbols themselves
ought to be chosen so that they are not likely to be accidentally used as
variables in somebody's program.  Around here, "unix" and "waterloo" are
predefined, and who knows what else is?  If predefined symbols were all to
begin and end with underscore characters, and this fact were documented,
then nobody would fall into the trap of inadvertently using one.

dave@utcsrgv.UUCP (Dave Sherman) (07/09/84)

In article <297@watdcsu.UUCP> geo@watdcsu.UUCP (Geo Swan) writes:
~|\I agree with the need for standards.
~|\Further, these standards should be properly documented.
~|\I learned that cpp automatically sharp defined "unix",
~|\when I tried to declare a variable named "unix".  (Try it sometime.)

Actually, it wouldn't matter if the implementors had had the sense
to have cpp implcitly "#define unix unix", instead of "#define unix 1".
The first would still permit all "#ifdef unix" work, while the actual
implementation caused me grief one day when I tried to create a
function called unix()

Dave Sherman
Toronto
-- 
 {allegra,cornell,decvax,ihnp4,linus,utzoo}!utcsrgv!dave
or
 David_Sherman%Wayne-MTS%UMich-MTS.Mailnet@MIT-Multics.ARPA

dmmartindale@watcgl.UUCP (Dave Martindale) (07/10/84)

I think that, once upon a time, the preprocessor *did* #define unix unix.
But at the point that cpp began accepting #if in addition to #ifdef,
the default value of defined parameters changed from themselves to 1.
You can use "1" in both #if and #ifdef.

andrew@orca.UUCP (Andrew Klossner) (07/12/84)

[]

	"Actually, it wouldn't matter if the implementors had had the
	sense to have cpp implcitly "#define unix unix", instead of
	"#define unix 1".  The first would still permit all "#ifdef
	unix" work, while the actual implementation caused me grief one
	day when I tried to create a function called unix()"

Nope.  "#define unix unix" followed by a use of "unix" will put the
preprocessor into a loop, scanning "unix" over and over, until the
recursion depth is hit and it punts with a fatal error message.

Here's what it does under 4.2BSD:

	% cat >unix.c
	#define unix unix
	unix() {}
	% cc unix.c
	unix.c: 1: unix redefined
	unix.c: 2: unix: macro recursion
	% 

  -- Andrew Klossner   (decvax!tektronix!orca!andrew)      [UUCP]
                       (orca!andrew.tektronix@rand-relay)  [ARPA]

henry@utzoo.UUCP (Henry Spencer) (07/13/84)

> Nope.  "#define unix unix" followed by a use of "unix" will put the
> preprocessor into a loop, scanning "unix" over and over, until the
> recursion depth is hit and it punts with a fatal error message.

Actually, back in the dawn of time, the magic symbol "unix" *was*
defined as itself.  This went out when the preprocessor was rewritten
and started rescanning macro expansions for more macros.

The ANSI C draft, incidentally, says that the macro name is temporarily
undefined within its own body, so that "#define unix unix" would work.
(Permitting recursive macros seems silly, since the only thing they can
do is provoke an error message (or a core dump!) from the preprocessor.)
The issue of being able to test the thing in #if is still important, though.
-- 
				Henry Spencer @ U of Toronto Zoology
				{allegra,ihnp4,linus,decvax}!utzoo!henry

dave@utcsrgv.UUCP (Dave Sherman) (07/15/84)

In article <936@orca.UUCP> andrew@orca.UUCP (Andrew Klossner) writes:
~| []
~| 
~| 	"Actually, it wouldn't matter if the implementors had had the
~| 	sense to have cpp implcitly "#define unix unix", instead of
~| 	"#define unix 1".  The first would still permit all "#ifdef
~| 	unix" work, while the actual implementation caused me grief one
~| 	day when I tried to create a function called unix()"
~| 
~| Nope.  "#define unix unix" followed by a use of "unix" will put the
~| preprocessor into a loop, scanning "unix" over and over, until the
~| recursion depth is hit and it punts with a fatal error message.
~| 

Why should that be true? Since the preprocessor is putting it in
implicitly anyway, it could easily have the smarts to skip over "unix"
in any re-scans of lines. This can obviously be made different from
a user-suppled "#define unix unix".

Dave Sherman
Toronto
-- 
 {allegra,cornell,decvax,ihnp4,linus,utzoo}!utcsrgv!dave
or
 David_Sherman%Wayne-MTS%UMich-MTS.Mailnet@MIT-Multics.ARPA

mzal@pegasus.UUCP (Mike Zaleski) (07/20/84)

Two that I've encountered:

	univac		Univac/1100 UNIX at Bell Communications Research.
	u3b2	    For the 3b2.

-- Mike^Z    allegra!pegasus!mzal    Zaleski@Rutgers

jr@foros1.UUCP (John Rogers) (07/25/84)

Hi.  I've been trying to keep a list of the various predefined symbols;
it's based on one by Steve Bourne in "The UNIX System" (page 99),
Martin Minow's recent posting, and my own research.  I don't have any
data on anything earlier than V7.  If anyone has any additions or
corrections, please let me know, and I'll repost a new version of this
in a week or two.

	__DATE__	(Decus C - date of complation)
	__FILE__	(file name of source file - most preprocessors)
	__LINE__	(line number within current source file - ditto)
	cpm		(CP/M - see the "p" preprocessor in Jul-84 Dr. Dobb's)
	decus		(Decus C for PDP-11 - RSX and RT-11)
	gcos		(Honeywell 6000 GCOS operating system?)
	ibm		(IBM - mainframes only, I assume? PCM's too?)
	interdata	(Interdata 8/32 - now Perkin Elmer something?)
	lint		(UNIX's C syntax & semantics checker)
	m68k		(Motorola's System V port for the 68000)
	mc68000		(Fortune's 32:16 and various other 68000's)
	mert		(BTL's old microprocessor real-time system?)
	nomacarg	(Decus C - means it doesn't support #define args)
	os		(IBM's OS for System/360 and System/370)
	pdp11		(DEC PDP-11: BTL C for UNIX; Decus C for RSX and RT-11)
	PWB		(the UNIX/PWB programmer's workbench system)
	RES		(UNIX - research??????)
	rsx		(Decus C under the RSX operating system for PDP-11)
	RT		(the UNIX/RT real-time system?)
	sun		(SUN workstation?)
	TS		(the UNIX/TS timesharing system?)
	tss		(IBM's Time Sharing System?)
	unix		(the you-know-what operating system)
	u370		(UNIX on IBM 370's?)
	u3b		(UNIX on 3B series?)
	u3b5		(UNIX on 3B5?)
	vax		(DEC VAX (UNIX or VMS) - also some Unisoft 68000 ports!)
	vax11c		(DEC's VAX-11 C for VMS)
	vms		(DEC's VAX-11 C for VMS)

Other possibilities include:

	ccpm86		(Concurrent CP/M-86)
	cpm68k		(CP/M-68K)
	cpm80		(CP/M-80)
	cpm86		(CP/M-86)
	gnu		(Stallman's (sp?) GNU - GNU's Not UNIX)
	i8080		(Intel 8080-compatible: 8080, 8085, Z80)
	i8086		(Intel 8086 and 8088 processors)
	i80186		(Intel 80186 and friends)
	i80286		(Intel 80286 and friends)
	mpm		(Digital Research's MP/M)
	msdos		(Microsoft's MS-DOS operating system)
	pcdos		(IBM and/or Microsoft's PC-DOS operating system)
	xinu		(Purdue's XINU - XINU Is Not UNIX)
	z80		(Zilog Z80)
	z800		(Zilog Z800, if they ever ship any)
	z8000		(Zilog Z8000, if anyone still uses them)

Does anyone have any data on Coherent?  Idris?  Any MS-DOS C compilers?
Whitesmiths?  National 16032/32016/whatever?  Amdahl's UTS?  OS-9? S1?
Eunice?  Cray computers?  This table could certainly get a lot larger! :-)

				See ya!
-- 
				JR (John Rogers)
				...ihnp4!fortune!foros1!jr
				also fortune!jr and proper!jr