Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!henry From: henry@utzoo.UUCP (Henry Spencer) Newsgroups: comp.lang.c Subject: Re: another auto-increment problem Message-ID: <8672@utzoo.UUCP> Date: Mon, 28-Sep-87 21:59:21 EDT Article-I.D.: utzoo.8672 Posted: Mon Sep 28 21:59:21 1987 Date-Received: Mon, 28-Sep-87 21:59:21 EDT References: <3680001@wdl1.UUCP> Organization: U of Toronto Zoology Lines: 22 > ... all our UNIX systems have > implementations that evaluate function arguments right to left!! > > I presume this has something to do with the order in which the > arguments have to be pushed and popped on the stack... As various people have pointed out, the order in which arguments are evaluated is officially undefined, and you are warned not to depend on it. This got started mainly, I believe, because the earliest C compiler used right-to-left evaluation. The reason for right-to-left is in two parts. First, functions like printf are a lot easier to implement if arguments, once pushed, are in ascending order in memory, e.g. argument 3 follows argument 2. Second, many modern machines have stacks that grow downward in memory, i.e. the latest thing pushed is below the previous thing pushed; the PDP11 did it that way for complex reasons, and many others have copied the 11. Putting these two considerations together, if the leftmost argument is to be at the lowest location in memory, it must be pushed last. Hence right-to-left. -- "There's a lot more to do in space | Henry Spencer @ U of Toronto Zoology than sending people to Mars." --Bova | {allegra,ihnp4,decvax,utai}!utzoo!henry