printf() problem

Paul Hudson paul at moncam.co.uk
Thu Apr 27 19:12:39 AEST 1989


In article <89Apr26.092233edt.18850 at me.utoronto.ca>, zougas at me.utoronto.ca ("Athanasios(Tom) Zougas") writes:
> In article <11657 at hodge.UUCP> jdm at 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 at moncam.co.uk,
		  FAX: +44 (223) 420911		 ...!ukc!acorn!moncam!paul
"/dev/null full: please empty the bit bucket"



More information about the Comp.lang.c mailing list