Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.csd.uwm.edu!cs.utexas.edu!usc!orion.cf.uci.edu!uci-ics!schmidt@glacier.ics.uci.edu From: schmidt@glacier.ics.uci.edu (Doug Schmidt) Newsgroups: comp.lang.c Subject: function call argument evaluation and global variables Message-ID: <21448@paris.ics.uci.edu> Date: 22 Aug 89 21:12:11 GMT Sender: news@paris.ics.uci.edu Reply-To: schmidt@glacier.ics.uci.edu (Doug Schmidt) Organization: University of California, Irvine - Dept of ICS Lines: 51 Hi, I've got a short question. Does the ANSI C standard place any restrictions on the evaluation of parameters to functions? In particular, is the following program portable in a fully conforming ANSI C compiler (I know it `fails' on non-ANSI C compilers): ---------------------------------------- int number = 100; int bar () { return number += 1000; } foo (a, b) int a, b; { printf ("%d, %d, %d\n", a, b, number); } main () { foo (number, bar ()); } ---------------------------------------- This program prints 1100, 1100, 1100 if function bar () is evaluated before global variable `number.' On the other hand, the program prints 100, 1100, 1100 if the evaluation is reversed. I realize that to be portable one should not really upon such behavior; I'm just interested to know whether the standard defines the behavior here, or whether it is `caveat programmer!' thanks, Doug -- schmidt@ics.uci.edu (ARPA) | Per me si va nella citta' dolente. office: (714) 856-4043 | Per me si va nell'eterno dolore. | Per me si va tra la perduta gente. | Lasciate ogni speranza o voi ch'entrate.