Path: utzoo!utgpu!news-server.csri.toronto.edu!clyde.concordia.ca!mcgill-vision!snorkelwacker!bu.edu!rpi!zaphod.mps.ohio-state.edu!wuarchive!uunet!mcsun!hp4nl!sci.kun.nl!cs.kun.nl!eerke From: eerke@cs.kun.nl (Eerke Boiten) Newsgroups: comp.theory Subject: Re: Procedures with multiple out parameters: why not? Message-ID: <2118@wn1.sci.kun.nl> Date: 27 Aug 90 08:29:58 GMT References: <1990Aug15.231838.5664@zaphod.mps.ohio-state.edu> <4625@uqcspe.cs.uq.oz.au> Sender: root@sci.kun.nl Followup-To: comp.lang.misc Organization: University of Nijmegen, The Netherlands Lines: 36 In article <4625@uqcspe.cs.uq.oz.au> ianh@batserver.cs.uq.oz.au writes: []I suspect the theoretical problem that Dijkstra is referring to is []aliasing of variables. For example, consider [example deleted] []Another more practical example is the following matrix []multiplication procedure [] procedure MatrixMultiply(var A, B, C : matrix); []Here the A and B are passed as var parameters even though they are []not being modified by the matrix multiplication procedure. However, []if we have a call of the form [] MatrixMultiply(M,M,M) []we will not get the result that we want as A, B and C will all be []aliases for the same matrix M. To avoid this problem we need the []header to read [] procedure MatrixMultiply( A, B : matrix; var C : matrix) []this avoids any aliasing problems and will work correctly for the []call [] MatrixMultiply(M,M,M). What I'm going to say is pretty obvious if you're a regular Pascal programmer, but since this is comp.theory ... In answer to the question that arises: why would anyone declare *all* arguments as *var* arguments? most Pascal implementations put *adresses* of var-arguments on the stack, whereas *values* of non-var arguments are stacked when a procedure/function call occurs. Thus, when one has *matrix* (read: large) arguments, one usually makes them var-parameters. Note that thus Ian Hayes' example shows that no everywhere-correct & efficient Pascal matrix multiplication procedure can exist. (Or am I overlooking something? If I did, we might continue on comp.lang.misc) Eerke Boiten Department of Informatics (STOP Project), K.U.Nijmegen Toernooiveld, 6525 AD Nijmegen, The Netherlands Tel. +31-80-612236. Email: eerke@cs.kun.nl