Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site utcs.UUCP Path: utzoo!utcs!geoff From: geoff@utcs.UUCP (Geoff Collyer) Newsgroups: net.lang.c Subject: ugliness in scanf(3) Message-ID: <649@utcs.UUCP> Date: Tue, 14-May-85 01:46:55 EDT Article-I.D.: utcs.649 Posted: Tue May 14 01:46:55 1985 Date-Received: Tue, 14-May-85 02:31:04 EDT References: <10496@brl-tgr.ARPA> <190@mplvax.UUCP> <504@umd5.UUCP> <10600@brl-tgr.ARPA> Reply-To: geoff@utcs.UUCP (Geoff Collyer) Organization: University of Toronto - General Purpose UNIX Lines: 40 Keywords: printf scanf stdio manuals rewrites Summary: scanf(3S) and printf(3S) need a re-write In article <10600@brl-tgr.ARPA> gwyn@brl-tgr.ARPA (Doug Gwyn) writes: >> ... I can *answer* questions from users too *lazy* to *read* >> the manuals... > >UNIX was developed by and for intelligent programmers. printf(3S) and scanf(3S) are incomplete and slippery specifications. If you doubt this, try writing the code from the manual pages. The current manual pages (and source code?) seem to be descended from the v6 Portable C library (-lp) and have never been substantially modified. The v7 printf(3S) implies that one can supply a format specifier of %lu to print an unsigned long int. The v7 C compiler doesn't support unsigned longs, yet %lu will print a long int as if it were unsigned. It is possible to express this in C (assuming twos-complement representation) by heroic measures. What should printf do when given the format specifier %017s and a string shorter than 17 characters? I read printf(3S) as saying that printf will pad with zeroes, though the v7 printf (at least) pads with blanks and Dennis Ritchie has argued that this is desirable behaviour. Various of System III or V don't support zero padding when the field width begins with a zero. AT&T has converted this incompatible behaviour from a bug into a feature by documenting it (at least in System V). To date, ANSI has wisely sided against AT&T in this case. scanf(3S) implies that inappropriate characters in the input will be left unread, but this is not possible, given stdio's (zero or) one character of pushback, for pathological input such as 3.4e-z under %f; the best one can do is to push back the z, though all of e-z should be pushed-back. At a quick glance, the draft ANSI C library write-ups for printf and scanf seem better than the UNIX manual pages, though still not as explicit as I would like. -- "All I'm after is just a *mediocre* brain, something like the president of the AT&T Company." - Alan Turing