Path: utzoo!attcan!uunet!munnari!otc!metro!pta!teti!nswitgould!ausonics!greyham From: greyham@ausonics.OZ (Greyham Stoney) Newsgroups: comp.unix.wizards Subject: Re: Problem with printf() Message-ID: <50@ausonics.OZ> Date: 13 Oct 88 04:46:37 GMT References: <504@imec.UUCP> Organization: Ausonics Pty Ltd, Sydney, Australia Lines: 26 in article <504@imec.UUCP>, croes@imec.uucp (Kris Croes) says: > main() > { > int i = 17; > float f = 17.0; > > printf("%d %f\n",i,i); /*1*/ > printf("%d %f\n",f,f); /*2*/ ^^ ^ > } You have indeed broken the law. These sort of things just aren't defined; the ENTIRE output of BOTH printfs will be garbage (machine/compiler/system- dependant == garbage). float and ints probably (do usually) have different sizes, so a different ammount of info is passed for each one. When printf skips the space for the first 'f' in the arg list, it is actually skipping sizeof(int), cos that's what you told it was there; so it lands in the middle of the float when it looks for the second argument. > 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. (???) Yes it is.... you lied when you told it what the stack looked like. -- # Greyham Stoney: (disclaimer not necessary: I'm obviously irresponsible) # greyham@ausonics.oz - Ausonics Pty Ltd, Lane Cove. (* Official Sponsor *)