Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.milw.wisc.edu!lll-winken!uunet!mitel!sce!sunray!jimp From: jimp@sunray.UUCP (Jim Patterson) Newsgroups: comp.lang.c Subject: Re: printf() problem Keywords: C printf Message-ID: <6006@sunray.UUCP> Date: 29 Apr 89 20:43:54 GMT References: <11657@hodge.UUCP> <89Apr26.092233edt.18850@me.utoronto.ca> Reply-To: jimp@cognos.UUCP (Jim Patterson) Organization: Cognos Inc., Ottawa, Canada Lines: 20 In article <89Apr26.092233edt.18850@me.utoronto.ca> zougas@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