Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!seismo!uwvax!oddjob!gargoyle!ihnp4!ihlpg!ejbjr From: ejbjr@ihlpg.ATT.COM (Branagan) Newsgroups: comp.lang.c Subject: Re: Passing (char *) NULL to printf to match %s Message-ID: <3533@ihlpg.ATT.COM> Date: Mon, 27-Jul-87 16:30:45 EDT Article-I.D.: ihlpg.3533 Posted: Mon Jul 27 16:30:45 1987 Date-Received: Tue, 28-Jul-87 07:18:28 EDT References: <166@qetzal.UUCP> <157@hobbes.UUCP> <875@bsu-cs.UUCP> Organization: AT&T Bell Laboratories - Naperville, Illinois Lines: 21 Summary: kludge > > printf("%s", (char *) NULL); says print the string at address 0. This > > happens to work on a VAX because that machine SPECIFICALLY has set things > > up so that the contents of location 0 is 0. This bad coding practice > > hits owners of Sun machines as well and is NOT a compiler bug. > The "correct" behavior today, according to ANSI C as > I know it, is for printf to print a token signifying that a NULL > pointer was passed. Microsoft C will print the string "(null)" when > this happens. Some time ago I noticed one of our VAXes printing a NULL pointer as "(null)". I thought it was neat that printf now detected NULL string pointers and did something sensible, until I found out that this only worked because the loader stored the string "(null)" at location 0. This apparently broke so many other programs it was backed out, and location 0 now has a 0 in it again. Oh well... -- ----------------- Ed Branagan ihnp4!ihlpg!ejbjr (312) 369-7408 (work)