kyle@xanth.UUCP (Kyle Jones) (07/25/87)
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 aed aea
guy%gorodish@Sun.COM (Guy Harris) (07/25/87)
> 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
gwyn@brl-smoke.ARPA (Doug Gwyn ) (07/25/87)
In article <1667@xanth.UUCP> kyle@xanth.UUCP (Kyle Jones) writes: >Do anyone know if printf() used to handle "%D", etc. as outlined above? It used to, but don't rely on it. Use %ld etc. instead.
ark@alice.UUCP (07/27/87)
In article <1667@xanth.UUCP>, kyle@xanth.UUCP writes: > 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? Once upon a time, printf used to use %D, %O, %X to mean the same thing as %ld, %lo, %lx, respectively. More recent printf implementations leave %D and %O undefined and use %X to print an integer in hex using uppercase ABCDEF. Similarly for %E, %F, and %G (that is, print 3E10 instead of 3e10). %ld prints a long in all implementations, and similarly for %lo, %lx, and %lu. This dichotomy is mostly my fault. Sorry about that. --Andrew Koenig
wagner@iaoobelix.UUCP (07/27/87)
I vaguely remember having read that the uppercase versions of %[dox] are just supported for the sake of compatibility, and that they are likely to disappear in future releases of `printf'. However, don't ask me where I have read this! In the SunOS3.2 man pages, uppercase control letters for %[dox] are not mentioned, either. Yet, I reckon this doesn't present any severe problems (does anybody prefer them at all??). Juergen Wagner, (USENET) ...seismo!unido!iaoobel!wagner ("Gandalf") Fraunhofer Institute IAO, Stuttgart
hunt@spar.SPAR.SLB.COM (Neil Hunt) (07/27/87)
>> 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? > >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.) Notice that in [fs]scanf there is a similar problem, and here the capitalising convention is still used (in Sun 3.2, at least): The conversion chanacters d, u, o, and x may be capitalized or preceded by l or h to indicate that a pointer to long or to short rather than to int is in the argument list. Simi- larly, the conversion characters e, f, and g may be preceded by l to indicate that a pointer to double rather than to float is in the argument list. Neil/.
pozar@hoptoad.uucp (Tim Pozar) (07/27/87)
In article <1667@xanth.UUCP> kyle@xanth.UUCP (Kyle Jones) writes: >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? In MSC 4.0 (I can't remember if its the case for 2 and 3 also) there is a difference with the ouput of a number using the lowercase "%x" and an uppercase "%X". With the uppercase the hex string will be in upper case (eg. 5FE), and with the lowercase the hex string will be in lowercase (eg 5fe). -- Tim Pozar UUCP pozar@hoptoad.UUCP Fido 125/406 USNail KLOK-FM 77 Maiden Lane San Francisco CA 94108