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,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,9d66743a9fdd96bd X-Google-Attributes: gid103376,public From: Stephen Leake Subject: Re: question about functions Date: 2000/01/27 Message-ID: #1/1 X-Deja-AN: 578414988 References: <867e3p$8ph$1@news.mgn.net> X-Complaints-To: dscoggin@cne-odin.gsfc.nasa.gov X-Trace: skates.gsfc.nasa.gov 948997445 13446 128.183.220.71 (27 Jan 2000 18:24:05 GMT) Organization: NASA Goddard Space Flight Center NNTP-Posting-Date: 27 Jan 2000 18:24:05 GMT Newsgroups: comp.lang.ada Date: 2000-01-27T18:24:05+00:00 List-Id: "Matthew Heaney" writes: > In article , Stephen Leake > wrote: > > > In any case, I have often successfully used 'Address on subprogram > > parameters that are not of a by-reference type, with both ObjectAda > > and GNAT, so at least some compilers go beyond the implementation advice. > > Of course it *may* work, but you are depending on an implementation > specific feature, namely the parameter passing mechanism used for > composite types. > > Even within one compiler, an array may be passed by value if it's > "small" enough. This is getting confusing, but I think it's important, so let me try to be clear. Suppose I have a procedure that does matrix multiply, written in assembly. It takes the address of the operands and result as parameters: procedure Assem_Mat_Mul (A, B, C : in System.Address); -- C = A x B, all 3 x 3 matrices Now I want to wrap that in a properly typed Ada procedure: type Matrix is array (1 .. 3, 1 .. 3) of Float; procedure Ada_Mat_Mul (A, B : in Matrix; C : out Matrix) is begin Assem_Mat_Mul (A'Address, B'Address, C'Address); end Ada_Mat_Mul; I claim Ada_Mat_Mul is independent of the parameter passing mechanism used for C. If C is passed by copy, 'Address will give the address of the copy, Assem_Mat_Mul will write the result there, and the result will be copied out when Ada_Mat_Mul returns. If C is passed by reference, 'Address will give the address of the actual parameter, Assem_Mat_Mul will write the result there. On the other hand, if the compiler vendor chooses to _only_ provide the support for 'Address required by 13.3 (16), then C'Address is invalid, whether C is passed by copy or reference. This is because C is neither aliased nor of a by-reference type. So you can say Ada_Mat_Mul is not "very" portable, because it relies on vendors going beyond the implementation advice in 13.3 (16). But it does _not_ depend on the parameter passing mechanism. -- Stephe