Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!rutgers!mit-eddie!ll-xn!adelie!mirror!frog!john From: john@frog.UUCP (John Woods) Newsgroups: comp.lang.c Subject: Re: An interesting behaviour in printf Message-ID: <1133@frog.UUCP> Date: 21 Mar 89 00:51:00 GMT References: <960@Portia.Stanford.EDU> <15938@cup.portal.com> <2343@buengc.BU.EDU> Distribution: na Organization: Misanthropes-R-Us Lines: 36 In article <2343@buengc.BU.EDU>, bph@buengc.BU.EDU (Blair P. Houghton) writes: > In article <15938@cup.portal.com> Tim_CDC_Roberts@cup.portal.com writes: > >In <960@Portia.Stanford.EDU>, joe@hanauma (Joe Dellinger) asks: > >> string[0] = '*'; > >> string[1] = '\0'; > >> printf("%s\n", string[1]); > >Trivia question: is the '(null)' output of printf standard or widespread? > The uVAX/Ultrix C compiler ignores it whole. The only thing the program emits > is the \n. (I checked it by "funkyprint | od -bc". One char out. \012. > More interesting than I expected. Smells broken.) > The Encore/Umax C compiler emits \022 \012. So, like, what's \022? My > ASCII table says it's a "dc2". I'd bet dollars to holes in doughnuts that Ultrix's library (note: not the compiler) behaves that way because there are four zero-bytes at address 0. The first of them looks like an empty string (""). Or maybe they check for NULL and call it an empty string. The program running on the Encore probably sees \022\040\000 at address 0. A string with two characters, \022 and space. Note that there are some systems that could potentially bus-error instead of printing anything. To quote Henry's Ten Commandments, "2. Thou shalt not follow the NULL pointer, for chaos and madness await thee at its end." (a wonderful set of dicta for printing in Fraktur and posting on one's wall :-) UNOS' printf routine displays a NULL %s value as , a bit more verbose than (null) but equally useful. -- John Woods, Charles River Data Systems, Framingham MA, (508) 626-1101 ...!decvax!frog!john, john@frog.UUCP, ...!mit-eddie!jfw, jfw@eddie.mit.edu "He should be put in stocks in Lafeyette Square across from the White House and pelted with dead cats." - George F. Will