comp.lang.ada
 help / color / mirror / Atom feed
From: Stephen Leake <Stephen.Leake@gsfc.nasa.gov>
Subject: Re: question about functions
Date: 2000/01/27
Date: 2000-01-27T18:24:05+00:00	[thread overview]
Message-ID: <ur9f3l6l6.fsf@gsfc.nasa.gov> (raw)
In-Reply-To: mDjj4.5605$bp2.259445@newsread2.prod.itd.earthlink.net

"Matthew Heaney" <matthew_heaney@acm.org> writes:

> In article <uwvozl2hp.fsf@gsfc.nasa.gov> , Stephen Leake 
> <Stephen.Leake@gsfc.nasa.gov>  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




  reply	other threads:[~2000-01-27  0:00 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-01-20  0:00 question about functions Pascal LEJEUNE
2000-01-20  0:00 ` Stephen Leake
2000-01-22  0:00   ` Andy
2000-01-22  0:00     ` Matthew Heaney
2000-01-24  0:00     ` Stephen Leake
2000-01-22  0:00   ` Matthew Heaney
2000-01-24  0:00     ` Stephen Leake
2000-01-25  0:00       ` Matthew Heaney
2000-01-27  0:00         ` Stephen Leake [this message]
2000-01-24  0:00     ` Mats Weber
2000-01-20  0:00 ` Tucker Taft
2000-01-20  0:00 ` David Starner
2000-01-20  0:00 ` Hyman Rosen
  -- strict thread matches above, loose matches on Subject: below --
2000-01-21  0:00 Pascal LEJEUNE
2000-01-21  0:00 ` tmoran
2000-01-21  0:00   ` Samuel T. Harris
2000-01-21  0:00     ` Stephen Leake
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox