comp.lang.ada
 help / color / mirror / Atom feed
* Interfacing to C, output arrays
@ 1996-12-02  0:00 Simon Wright
  1996-12-02  0:00 ` Robert Dewar
  1996-12-10  0:00 ` Paul Chardon
  0 siblings, 2 replies; 5+ messages in thread
From: Simon Wright @ 1996-12-02  0:00 UTC (permalink / raw)



The code below shows an interface to a C function
  int accessor(int n, int* a);
which fills the n-element array a with data.

The code works just fine with Gnat 3.07 (OSF, Linux) but I think I may
be just 'lucky'.

The purpose of the subtype This_Arr is to make sure that the parameter
passed to the C code doesn't have any 'extraneous' constraint info at
the front (in fact, Gnat seems to pass the address of the first
element even to the Ada procedure anyway). Gnat warns that Result is
never assigned a value (that is, the Result out parameter to the Ada
procedure), so I'm concerned that another compiler might handle things
differently.

The Rationale doesn't cover the case of array parameters
(Interfaces.C.Pointers doesn't seem relevant here), but LRM B.3(70)
seems to indicate that I'm OK. Any thoughts?

--
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;




^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~1996-12-10  0:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-12-02  0:00 Interfacing to C, output arrays Simon Wright
1996-12-02  0:00 ` Robert Dewar
1996-12-03  0:00   ` Simon Wright
1996-12-07  0:00     ` Robert Dewar
1996-12-10  0:00 ` Paul Chardon

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