Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!purdue!mentor.cc.purdue.edu!mace.cc.purdue.edu!ags From: ags@mace.cc.purdue.edu (Dave Seaman) Newsgroups: comp.lang.pascal Subject: Re: Funny evaluation of functions Message-ID: <2974@mace.cc.purdue.edu> Date: 23 Aug 89 22:41:36 GMT References: <20693@adm.BRL.MIL> Reply-To: ags@mace.cc.purdue.edu (Dave Seaman) Organization: Purdue University Lines: 18 In article <20693@adm.BRL.MIL> fsbrn@BRL.MIL (VLD/LTTB) writes: [ You have all seen the funny program by now. ] >Remember that in Pascal you may not say > var num [1..MAX] of integer; > if (i <= MAX) AND (num[i] <> 17) >because the standard says the entire expression must be evaluated, but >also because it doesn't guarantee that the second expression won't be >evaluated before the first one (and because Pascal doesn't terminate >boolean expressions as soon as possible). It is not true that the entire expression must be evaluated. The standard says that an implementation MAY CHOOSE to evaluate the entire expression, but it isn't required, in general. In an expression like "x*one(x)", it would be possible to skip the evaluation of the function "one" if x happens to be zero. If "one" has side effects, then the result is implementation-dependent. Assuming that both terms are evaluated, they may be taken in either order.