%F vs. %lf and %D vs. %ld in printf/scanf

Guy Harris guy at sun.uucp
Fri Aug 16 18:43:02 AEST 1985


> Yes, I did realize that, but (and this is where the show really starts..)
> the problem I reported is one of NON-ORTHAGONALITY not implementation.
> Your explanation is quite correct, but why should I (as a programmer)
> have to worry about translation to stack? Why doesn't printf take 
> %F and %D and translate for me so that the orthagonality of the two
> system calls (which are considered by most to be related functions)
> is the same?

Because there is a very natural (and very useful) interpretation for %X and
%E which are *not* equivalent to %lx and %le - namely, print the number with
upper-case "A-F" or upper-case "E".  This approach is taken by System V and
by the ANSI C standard (at least in the November 1984 draft (and by Sun 4.2,
and, I believe, everybody's 4.3).  If you use "%ld" and "%lf" in both
"printf" and "scanf", you will have code that works on all those systems
(and, I believe, on V7 as well); if you use %D or %F, you have code that
doesn't work on some of those systems and doesn't work one bit better on the
others.  (The ANSI C standard, November 1984 draft, states, BTW, that "l"
applied to "f", "e", or "g" in a "printf" control string is ignored, since
you can't pass a "float" without it being widened into a double; this is
implemented by 4.2 VAX, 4.2 Sun, and S5.)

If you use "%l<whatever>" for doubles and longs, and "%<whatever>" for
floats and ints, you achieve most of the orthogonality you want.  If
"printf" treated "%h<whatever>" just like "%<whatever>", you'd get the rest
of the orthogonality, since you'd use "%h<whatever>" for shorts.

	Guy Harris



More information about the Comp.lang.c mailing list