Xref: utzoo comp.unix.wizards:11646 comp.lang.c:13211 Path: utzoo!attcan!uunet!seismo!sundc!pitstop!sun!quintus!ok From: ok@quintus.uucp (Richard A. O'Keefe) Newsgroups: comp.unix.wizards,comp.lang.c Subject: Re: Problem with printf() Message-ID: <516@quintus.UUCP> Date: 10 Oct 88 04:00:52 GMT References: <504@imec.UUCP> <429@nikhefk.UUCP> Sender: news@quintus.UUCP Reply-To: ok@quintus.UUCP (Richard A. O'Keefe) Organization: Quintus Computer Systems, Inc. Lines: 21 In article <429@nikhefk.UUCP> tomp@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.