From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: * X-Spam-Status: No, score=1.3 required=5.0 tests=BAYES_00,HEADER_SPAM, INVALID_DATE,MSGID_SHORT,REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 Xref: utzoo comp.lang.ada:4828 comp.compilers:1715 Path: utzoo!mnetor!tmsoft!torsqnt!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!zaphod.mps.ohio-state.edu!think.com!mintaka!spdcc!iecc!compilers-sender From: mfeldman@eesun.gwu.edu (Michael Feldman) Newsgroups: comp.lang.ada,comp.compilers Subject: Re: ADA Compiling Query Keywords: Ada, question Message-ID: <2710@sparko.gwu.edu> Date: 12 Feb 91 19:01:29 GMT References: <5572@baird.cs.strath.ac.uk> Sender: compilers-sender@iecc.cambridge.ma.us Reply-To: mfeldman@eesun.gwu.edu (Michael Feldman) Followup-To: comp.lang.ada Organization: The George Washington University, Washington D.C. List-Id: In article <5572@baird.cs.strath.ac.uk> Gordon Russell writes: > >procedure MAIN is > variable1 : integer; > result : integer; >---------------------------------------------------- > procedure GET_RESULT(variable2: in out integer) is > begin > variable1=2; > variable2=variable1 + variable2; > end GET_RESULT; >---------------------------------------------------- > begin > variable1=10; > get_result(variable1); > end MAIN; Please don't take this as a flame, Gordon; I'm posting it for others' use as well. The critique is not of the syntax errors, nor of the fact that this classical aliasing problem is poor style (which you point out), but the fact that the answer to this question is readily available in the LRM, namely sect. 6.2, in which it states quite clearly that this parameter is passed by copy-in/copy-out. This means that GET_RESULT is working on a local copy of variable1 (in its alias as variable2). For a _scalar_ parameter, the parameter semantics is well-defined. For a parameter of a _composite_ type, it's not: the implementation can choose copy-in/copy-out _or_ reference passing. This would have made your question more interesting. Here's an exercise I give to my classes, when we discuss this stuff: for some compiler you have access to, prove that the scalar passing is by value/result (aka copy-in/copy-out), and write programs to demonstrate the behavior of passing for composite types. Hint: most compilers use reference passing for large arrays (common sense, no?); some use value/result for small arrays. If the latter, find the "crossover". [This exercise is to create a _purposely_ erroneous program: we _want_ its behavior to depend on the mechanism :-)] The LRM is really a good source of information. Serious Ada folks should have it and use it. Mike Feldman -- Send compilers articles to compilers@iecc.cambridge.ma.us or {ima | spdcc | world}!iecc!compilers. Meta-mail to compilers-request.