Problem with printf()

Richard A. O'Keefe ok at quintus.uucp
Mon Oct 10 14:00:52 AEST 1988


In article <429 at nikhefk.UUCP> tomp at nikhefk.UUCP (Tom Ploegmakers) writes:
>This one has bitten me once too.
>The problem is that floats are not passed to functions on the stack, but by
>passing a pointer.

The problem is simply that when you pass a parameter to any function in
pre-ANSI C, or to a function for which no prototype is in scope in dpANS C,
(or in the "..." part of a call to a function which takes a variable
number of arguments, such as printf()), the compiler is obliged to widen
integral expressions to 'int' and floating-point expressions to 'double'.
Thus when you do
	printf("...%d...%f...", f, f)
f is widened to double:  it is as if you did
	printf("...%d...%d...", (double)f, (double)f)

Look up "argument conversions" in your favourite C textbook
(page 135 in Harbison & Steele).

If all else fails, it sometimes pays to look at the code your compiler
generates.  UNIX "C" compilers have a "-S" flag.  Or you can use a
debugger on the object file.



More information about the Comp.unix.wizards mailing list