printf() problem

Doug Gwyn gwyn at smoke.BRL.MIL
Thu Apr 27 01:33:12 AEST 1989


In article <11657 at hodge.UUCP> jdm at hodge.UUCP (jdm) writes:
>        printf("%x %x %x %x\n", getc(fp), getc(fp), getc(fp), getc(fp));

The order of evaluation of function arguments in C is unspecified.
Some implementations evaluate the last argument first, others don't.
Since getc(fp) has a side effect (it advances an external stream),
the order of evaluation matters in this example, therefore the code
is not portable.  Your solution works, as would a succession of four
printf() invocations each printing one getc(fp) result.



More information about the Comp.lang.c mailing list