From owner-freebsd-stable Tue Oct 16 6: 7:14 2001 Delivered-To: freebsd-stable@freebsd.org Received: from thrush.ravenbrook.com (thrush.ravenbrook.com [193.112.141.249]) by hub.freebsd.org (Postfix) with ESMTP id C11E237B405 for ; Tue, 16 Oct 2001 06:07:11 -0700 (PDT) Received: from thrush.ravenbrook.com (localhost [127.0.0.1]) by thrush.ravenbrook.com (8.11.6/8.11.6) with ESMTP id f9GD69r10874; Tue, 16 Oct 2001 14:06:09 +0100 (BST) (envelope-from nb@thrush.ravenbrook.com) From: Nick Barnes To: Zero Sum Cc: cjclark@alum.mit.edu, "Crist J. Clark" , Heath Nielson , Warner Losh , David Marker , freebsd-stable@FreeBSD.ORG Subject: Re: setenv() cores with NULL value [was Re: Gdm proplem on 4.4] In-Reply-To: Message from Zero Sum of "Tue, 16 Oct 2001 20:02:11 +1000." <200110161002.f9GA2CA08544@shalimar.net.au> Date: Tue, 16 Oct 2001 14:06:09 +0100 Message-ID: <10872.1003237569@thrush.ravenbrook.com> Sender: owner-freebsd-stable@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG At 2001-10-16 10:02:11+0000, Zero Sum writes: > On Tuesday 16 October 2001 18:38, Crist J. Clark wrote: > > > > > > > setenv("TEST1", "", 1); > > > setenv("TEST2", NULL, 1); > > > > A huge difference. In the first case, the second argument is a > > pointer aimed at a string which contains the bytes, '\0'. In the > > second case, we have a null pointer. Null pointers point at nothing. > > I had that out with a compiler manufacturer long, long ago. At that > time it was a requirement for a 'correct' C compiler to regard a null > pointer and a pointer to a null string as sematically equivalent. > > Has this changed without me noticing? It was never generally true. Your memory may have its roots in the fact that some operating systems on some machines in the early 80s (VMS on VAXen, ISTR) wired page zero to be zero on read, discard on write, so that you could read from a NULL pointer (which was address zero in that -- and most -- implementations of C) and get zero bytes. On such a machine you could indeed pass NULL to a function that was expecting a string and get the same behaviour as passing a pointer to an empty string. This kind of hack saves a few lines of source code, a few bytes of object code, and a few CPU cycles. The cost in terms of portability and maintainability is immense. Nobody does it any more. This should go to -chat. Nick Barnes Ravenbrook Limited To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-stable" in the body of the message