Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Pascal Assignment statements

1 view
Skip to first unread message

Simon Wail

unread,
Oct 4, 1989, 11:23:10 PM10/4/89
to
I have a question about expression evaluation in assignment statements in
Standard Pascal.

Q. Is all address calculations of the assignment variable performed before
the expression on the R.H.S. is evaluated???

Some examples that cause problems :

x[a+b] := f;

where "f" is a function that modifies the global variables "a" and "b"
which are used to index the array on the L.H.S. Is the index to the
array calculated before "f" is called???

x[5].ptr^.y := f;

where "f" is a function that modifies the fifth element of the
array "x" so "ptr" points to a different record. Is the old value
of "ptr" used to modify "y" or the new value of "ptr" changed
in "f"????

I know these are examples of terrible side-effects and bad programming style,
but when one is writing a Pascal compiler it is necessary to take into account
all the possibilities and to be consistent when evaluating expressions.

Thanks.
-------------------------------------------------------------------------------
Simon Wail,
Post Graduate Student.

ACSnet: rc...@koel.co.rmit.oz UUCP: ...!uunet!munnari!koel.co.rmit.oz!rcosw
PHONE: + 61 3 660 2726 ARPA: rcosw%koel.co...@uunet.uu.net

RMIT / CSIRO Parallel Systems Architecture Project,
Department of Communication and Electrical Engineering,
Royal Melbourne Institute of Technology,
P.O. Box 2476V,
Latrobe St, Melbourne. 3000. Australia.

Doug Reeder

unread,
Oct 7, 1989, 7:46:28 AM10/7/89
to
In article <7...@chudich.co.rmit.oz> rc...@koel.co.rmit.oz (Simon Wail) writes:

>Q. Is all address calculations of the assignment variable performed before
> the expression on the R.H.S. is evaluated???

>Some examples that cause problems :

>x[a+b] := f;

> where "f" is a function that modifies the global variables "a" and "b"
> which are used to index the array on the L.H.S. Is the index to the
> array calculated before "f" is called???


From "Pascal For Programmers" by Lecarme & Nebutt (McGraw-Hill 1984) p27-28:

"The order in which the two sides of the assignment statement are evaluated
is implementation-dependent; i.e., a correct program must not depend on this
order."

Also, the terms in an expression are evaluated in an implementation-defined
manner. Thus, you can do whatever you like and don't even have to always do
the same thing. The book, by the way, is an excellent reference for the
experienced programmer. I consult mine all the time.

--
Doug Reeder USENET: ...!tektronix!reed!reeder
Box 722 Reed College BITNET: ree...@reed.BITNET
Portland, OR 97202 from ARPA: tektronix!reed!ree...@berkeley.EDU
(503) 777-1551 "A blaster can point two ways." -Salvor Hardin

0 new messages