Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!seismo!rutgers!labrea!decwrl!sun!gorodish!guy From: guy%gorodish@Sun.COM (Guy Harris) Newsgroups: comp.lang.c Subject: Re: printf's %D, %O, and %X Message-ID: <24183@sun.uucp> Date: Fri, 24-Jul-87 23:25:19 EDT Article-I.D.: sun.24183 Posted: Fri Jul 24 23:25:19 1987 Date-Received: Sat, 25-Jul-87 18:27:24 EDT References: <1667@xanth.UUCP> Sender: news@sun.uucp Lines: 44 > For a long time now I've been under the impression that using "%D"," %O", and > "%X" in a printf() conversion spec is equivalent to using "%ld", "%lo", and > "%lx". However when I looked at the documentation for printf (4.3 BSD) I > discovered that capitalizing "%d, "%o", and "%x" are not mentioned at all. > > Do anyone know if printf() used to handle "%D", etc. as outlined above? Well, it's like this: A long time ago, %[DOX] and %l[dox] were equivalent. Then somebody decided that it might be useful to print numbers whose display format included letters - i.e., hexadecimal and floating-point numbers - in a form that used capital letters. So, since %[DOX] were redundant, %[DO] were deprecated and %X was changed to mean "print an 'int' in hex with capital letters" rather than "print a 'long' in hex with lower-case letters". This change appeared in System III. 4.[12]BSD treated %[DOX] and %l[dox] as equivalent. I'd say "left them as equivalent", except that the 4.2BSD "doprnt" code is almost identical to the System V VAX "doprnt" code, except for the treatment of %[DOX], and it looks like that code originally behaved in the S3/S5 fashion, not the 4.[12]BSD fashion. 4.3BSD decided that %X meaning "print an 'int' in hex with capital letters" was a good idea, so they changed it (back?). The 4.3BSD manual mentions this interpretation of %X, as well as various other stuff from the S3 "printf" that it supports. (In fact, the 4.2BSD manual mentions this, despite the fact that it didn't support the new-style %X.) You should use %l[dox] rather than %[DOX], both because the former is supported by more C implementations than the latter and because the former is the form that's blessed by the current ANSI C draft standard (and likely to be the form blessed by the final standard). Furthermore, in some cases %D can screw you up; if a %D in a format string is followed by another %, all hell breaks loose if you check the file into SCCS, since that sequence is expanded to the current date when the file is gotten. (This fouled up a couple of utilities in 4.2BSD.) Guy Harris {ihnp4, decvax, seismo, decwrl, ...}!sun!guy guy@sun.com