From: dewar@merv.cs.nyu.edu (Robert Dewar)
Subject: Re: Interfacing to C, output arrays
Date: 1996/12/02
Date: 1996-12-02T00:00:00+00:00 [thread overview]
Message-ID: <dewar.849568380@merv> (raw)
In-Reply-To: x7viv6kmytr.fsf@pogner.demon.co.uk
Simon asks about:
with Interfaces.C;
package Inter is
type Arr is array (Integer range <>) of Interfaces.C.Int;
procedure Accessor (Result : out Arr);
end Inter;
package body Inter is
procedure Accessor (Result : out Arr) is
subtype This_Arr is Arr (Result'Range);
function Accessor (N : Interfaces.C.Int;
Result : This_Arr) return Interfaces.C.Int;
pragma Import (C, Accessor, "accessor");
Count : Interfaces.C.Int;
begin
Count := Accessor (N => Result'Length, Result => Result);
end Accessor;
end Inter;
And he surmises that RM B.3(70) makes this safe.
Well, I certainly think that GNAT is right to output a warning here, at
the least it is very ugly to have a C routine modifying an in parameter,
and indeed I think a compiler would be within its rights (though perhaps
not well advised) to assume that the function call could not modify the
array.
It would be much cleaner to pass an access to the array or to use a
procedure call and make the parameter out or in out.
Also note that RM B.3(70) is only implementation advice, not a requirement.
next prev parent reply other threads:[~1996-12-02 0:00 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
1996-12-02 0:00 Interfacing to C, output arrays Simon Wright
1996-12-02 0:00 ` Robert Dewar [this message]
1996-12-03 0:00 ` Simon Wright
1996-12-07 0:00 ` Robert Dewar
1996-12-10 0:00 ` Paul Chardon
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox