Xref: utzoo comp.unix.wizards:11595 comp.lang.c:13146 Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!bloom-beacon!husc6!bbn!uwmcsd1!marque!uunet!mcvax!prlb2!kulcs!kulesat!imec!croes From: croes@imec.uucp (Kris Croes) Newsgroups: comp.unix.wizards,comp.lang.c Subject: Problem with printf() Message-ID: <504@imec.UUCP> Date: 4 Oct 88 14:59:25 GMT Reply-To: croes@imec.UUCP (Kris Croes) Organization: IMEC, INTERUNIVERSITY MICROELECTRONICS CENTER, BELGIUM Lines: 38 Hello NetLand, May I introduce to you... A little program containing a big problem. main() { int i = 17; float f = 17.0; printf("%d %f\n",i,i); /*1*/ printf("%d %f\n",f,f); /*2*/ } Its output is: 17 0.000000 17032 0.000000 ^^^^^^^^ Shouldn't this be 17.00000 ? I am working under Ultrix 2.2, on a VAX-780 and had the same problem on Apollo. BTW sizeof(int) = sizeof(float) = 4 on both machines. Some tests (e.g. printing on several lines) showed that the problem is caused by printing the float under the "%d" format. I know that normal people don't do such a thing, but that is no reason for printf() to mess up the stack. (???) I know that not all binary numbers are valid floats. But if this was the case, it would give problems in line /*1*/. Why do things go wrong in line /*2*/ ? Is this a bug in my little program, in printf(), in C , or where ? K. Croes -- -------- K. CROES - IMEC - Leuven - Belgium ..!prlb2!imec!croes The Demon King sends a "rm -r /" to your shell.