Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watnot!watmath!clyde!rutgers!brl-adm!adm!welch%UMASS.BITNET@wiscvm.wisc.EDU From: welch%UMASS.BITNET@wiscvm.wisc.EDU Newsgroups: comp.unix.questions Subject: Evaluating autoincrements in function calls Message-ID: <4707@brl-adm.ARPA> Date: Thu, 26-Feb-87 12:21:51 EST Article-I.D.: brl-adm.4707 Posted: Thu Feb 26 12:21:51 1987 Date-Received: Sat, 28-Feb-87 04:58:10 EST Sender: news@brl-adm.ARPA Lines: 44 Here's an interesting C error/mis-feature I'd like to bring to your attention as a possible portability problem. int set[]={1,2,3}, i = 0; main() { printf("\nnumbers in set indexed by incr integer = %d,%d,%d", set[i++], set[i++], set[i++]); printf("\nnumbers in set indexed by constants = %d,%d,%d, set[0], set[1], set[2]); } The lattice C (V2.15) compiler produces: numbers in set indexed by incr integer = 1,2,3 numbers in set indexed by constants = 1,2,3 as output, while the Microsoft (V4.0) and VAX C (V2.2-015) compilers produce: numbers in set indexed by incr integer = 3,2,1 numbers in set indexed by constants = 1,2,3 In the second case the compiler is evaluating the arguments to the printf function right to left, including the autoincrement instructions, as it builds the stack. Lattice evaluates the autoincrement instructions left to right before pushing the arguments in the function call on the stack (from right to left). I don't want to be swamped with replies as to which set of results is correct but I would be interested to know if there is a standard which documents the correct behavior of argument evaluation. Jonathan Welch Bitnet: jhwelch@amherst