printf() problem

Jim Patterson jimp at sunray.UUCP
Sun Apr 30 06:43:54 AEST 1989


In article <89Apr26.092233edt.18850 at me.utoronto.ca> zougas at hammer.me.UUCP (Athanasios(Tom) Zougas) writes:
>C puts its function parameters on the stack in "reverse" order, i.e.
>the last item is on top (this allows variable number of parameters
>for user defined functions). It would happen in any C.

It doesn't happen in "any" C.  While reverse order is commonly chosen
by C implementations, in fact the order is deliberately left
unspecified by the language.  Other implementations will choose to
evaluate parameters in first to last order, or they could use first,
third, fourth, second in a given instance, etc.  A good compiler
might generate two results in registers, in order, and push them with
a single instruction. (I think the VAX/VMS C compiler might actually
do this using a VAX PUSHQ instruction). In short, don't rely on
evaluation order (and in particular avoid side-effect dependencies
like in the printf(getc(),getc()) example).
-- 
Jim Patterson                              Cognos Incorporated
UUCP:decvax!utzoo!dciem!nrcaer!cognos!jimp P.O. BOX 9707    
PHONE:(613)738-1440                        3755 Riverside Drive
                                           Ottawa, Ont  K1G 3Z4



More information about the Comp.lang.c mailing list