Path: utzoo!attcan!uunet!mcvax!ukc!acorn!moncam!paul From: paul@moncam.co.uk (Paul Hudson) Newsgroups: comp.lang.c Subject: Re: printf() problem Summary: Reverse-order isn't right, either. Keywords: C printf Message-ID: <163@marvin.moncam.co.uk> Date: 27 Apr 89 09:12:39 GMT References: <11657@hodge.UUCP> <89Apr26.092233edt.18850@me.utoronto.ca> Organization: Monotype ADG, Cambridge, UK Lines: 35 In article <89Apr26.092233edt.18850@me.utoronto.ca>, zougas@me.utoronto.ca ("Athanasios(Tom) Zougas") writes: > In article <11657@hodge.UUCP> jdm@hodge.UUCP (jdm) writes: > > > > Perhaps someone could explain this printf() phenomena to me. ... > > printf("%x %x %x %x\n", getc(fp), getc(fp), getc(fp), getc(fp)); > C puts its function parameters on the stack in "reverse" order, i.e. > ... No. C does not have any order defined for function evaluation. Typically compilers derived from pcc or that pass args. purely on the stack will push in reverse order, but even this isn't defined. Don't rely on it! > What you did will correct it. Or try: Sometimes, if the wind is in the right direction. > for ( i = 0; i < 4; ++i ) { > printf( "%x ", getc(fp) ); > } > you are losing in 5 calls of printf. Trade-offs, trade-offs ... The above works, the original doesn't, neither does the first fix always. > > It would happen in any C. No. See above. > Tom. > -- Paul Hudson MAIL: Monotype ADG, Science Park, Cambridge, CB4 4FQ, UK. PHONE: +44 (223) 420018 EMAIL: paul@moncam.co.uk, FAX: +44 (223) 420911 ...!ukc!acorn!moncam!paul "/dev/null full: please empty the bit bucket"