Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!seismo!ll-xn!cullvax!drw From: drw@cullvax.UUCP (Dale Worley) Newsgroups: comp.lang.c Subject: Passing NULLs to printf Message-ID: <1417@cullvax.UUCP> Date: Fri, 31-Jul-87 10:11:54 EDT Article-I.D.: cullvax.1417 Posted: Fri Jul 31 10:11:54 1987 Date-Received: Sat, 1-Aug-87 21:49:05 EDT Organization: Cullinet Software, Westwood, MA, USA Lines: 28 gwyn@brl-smoke.ARPA (Doug Gwyn ) writes: | In article <1407@cullvax.UUCP> drw@cullvax.UUCP (Dale Worley) writes: | > printf("%.0s", (char *)NULL) | >This should print zero characters out of the string, and so won't | >actually reference any character through the null pointer. Presumably | >this is valid ANSI C! | | No, why should it be? The printf() implementation may very well | always inspect the argument string to find its null terminator, | for example to determine its length before converting it. Eh? Well, certainly, if you do printf("%.100s", ...), you want it to work if the pointer doesn't point to a block of memory with a null byte in it? This is useful if you have a "string" stored in pointer/length format: printf("%.*s", len, ptr). Although I think that a careful reading of the ANSI document (p. 117, l. 26: "s format code: The argument shall be a pointer to a string." p. 84, l. 7: "A string is an array of characters terminated by a null character.") shows that I'm wrong. But this use of %s is useful and probably works in all implementations, and should be allowed. Dale -- Dale Worley Cullinet Software ARPA: cullvax!drw@eddie.mit.edu UUCP: ...!seismo!harvard!mit-eddie!cullvax!drw From the Temple of St. Cathode of Vidicon: