Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84 SMI; site sun.uucp Path: utzoo!linus!decvax!decwrl!sun!guy From: guy@sun.uucp (Guy Harris) Newsgroups: net.lang.c Subject: Re: if (p) ... Message-ID: <2910@sun.uucp> Date: Sun, 20-Oct-85 18:11:54 EDT Article-I.D.: sun.2910 Posted: Sun Oct 20 18:11:54 1985 Date-Received: Tue, 22-Oct-85 06:33:14 EDT References: <2098@brl-tgr.ARPA> <916@celtics.UUCP> Organization: Sun Microsystems, Inc. Lines: 46 > In fact, I've worked in an environment (PRIMOS and other Multics-style > systems) with segmented addressing schemes (and demand-paged virtual > memory) wherein the definition of a NULL pointer was any address in > the designated-highest-possible segment (defined as octal 7777). Thus, > for C to see a pointer as null required conversion from 7777/0 to 0 (or > seg 0 loc 0, which is a valid address) and back again! No, it didn't. The author of the C compiler may have thought so, but if he/she did then somebody else should have been chosen to write the compiler. On such a machine, 1) NULL should have been #defined as 0 (just like everywhere else) and 2) the statement if (p) foo(); should have compiled into something like compare_immediate p, #07777/0 # seg 7777, loc 0 beq around subroutine_call foo around: > YEAH, a portable test is necessary that does not depend on NULL being ZERO. The definition of the C language requires that NULL be ZERO (how many times do people have to be told this?). The test if (p) is already portable enough, as is the test if (p != 0) and the test if (p != NULL) In the aforementioned class of machines, all three test should compile into code like the code listed above. Guy Harris