Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watmath!clyde!rutgers!husc6!seismo!rochester!pt.cs.cmu.edu!ius2.cs.cmu.edu!edw From: edw@ius2.cs.cmu.edu.UUCP Newsgroups: comp.lang.c Subject: Re: Stupid evaluation ordering. Is this legal? Message-ID: <1104@ius2.cs.cmu.edu> Date: Sat, 18-Apr-87 16:57:16 EST Article-I.D.: ius2.1104 Posted: Sat Apr 18 16:57:16 1987 Date-Received: Sun, 19-Apr-87 08:20:51 EST References: <4395@hi.uucp> Organization: Carnegie-Mellon University, CS/RI Lines: 36 Keywords: K&R, Bible, PCs, UNIX In article <4395@hi.uucp>, josh@hi.uucp (Josh Siegel ) writes: > I just lost a argument and am running to the net for comfort... > > According to K&R(Bible) page 185, a C compiler is allowed to do the > following. > > Given: > > a(b()+c(),d()+e()) > > It is allowed to run functions b() and d(), then run > c() and e(), THEN add them (This has shades of > compilers that optimise on parallel machines). > This causes problems with stuff like: Never assume anything about the order of evaluation of parameters to a function. One thing, you are not guarenteed that b()+c() will be evaluated before d()+e(). I know, I had code break because of this very same thing. I'm not sure,but you may not even be guarenteed that b() will be evaluated before c(). Is it consider a legal optimization - to reorder the sequence of function calls within an expression? -- Eddie Wyatt They say there are strangers, who threaten us In our immigrants and infidels They say there is strangeness, too dangerous In our theatres and bookstore shelves Those who know what's best for us- Must rise and save us from ourselves Quick to judge ... Quick to anger ... Slow to understand... Ignorance and prejudice and fear [all] Walk hand in hand. - RUSH