comp.lang.ada
 help / color / mirror / Atom feed
* HELP: Interfaces.C...
@ 2000-04-06  0:00 Jack W. Sharer
  2000-04-11  0:00 ` Tucker Taft
  0 siblings, 1 reply; 2+ messages in thread
From: Jack W. Sharer @ 2000-04-06  0:00 UTC (permalink / raw)


This note is a request for help with the Ada package
            Interfaces.C
and its children.  I'm interfacing to MathWorks'
Matlab compute engine.  MathWorks provides this interface
as a "C" interface consisting of a compiled library
and C header (".h") files.  See
     <http://www-unix.umbc.edu/matlab/EIG.html>
under "Engine Routines" for a directory of this library.

I've been successful in accessing the compute engine
from Ada using the "Interfaces.C" package along with
its children.  The following code shows where I'm at
using gnat Ada on a Sun:
----------------- Begin Code Segment ---------------------
with System;
with Interfaces.C.Strings;
procedure Test is
   type Engine is new System.Address;
   procedure EngOutputBuffer
            ( Engine_Identifier: in Engine;
              Output_Buffer: out Interfaces.C.Char_Array;
              Buffer_Size: in Interfaces.C.Int );
   pragma Import (C, EngOutputBuffer, "engOutputBuffer");
   -- int engOutputBuffer(Engine *ep, char *p, int n);
   --     ep Engine pointer.
   --     p  Pointer to character buffer of length n.
   --     n  Length of buffer p.
   -- engOutputBuffer defines a character buffer for
   -- engEvalString to return any output that ordinarily
   -- appears on the screen.
   -- See <http://euler.shsu.edu/~jwang/techdoc/apiref/engoutputbuffer.html>
   -- From the ".h" file:
   --    typedef struct engine Engine;
   Ep: Engine;
   Matlab_Output: Interfaces.C.Char_Array(1..50000);
begin
-- ...
   EngOutputBuffer ( Ep,
                     Matlab_Output,
                     Interfaces.C.Int
                           ( Matlab_Output'Length ) );
-- ...
end Test;
------------------ End Code Segment ----------------------

While this code works, the form of the first and second
arguments appear to go against the spirit of the
Interfaces.C... packages.

From reading _Ada_as_a_Second_Language_, it appears that
the second argument should be of type
            Interfaces.C.Strings.chars_ptr
So following the information on page 986, I tried this:
------------------ Begin Code Segment --------------------
with Interfaces.C.Strings; use Interfaces.C.Strings;
procedure Test_Access is
   procedure EngOutputBuffer (
                              OutputBuffer: in Chars_Ptr
                              );
   pragma Import (C, EngOutputBuffer, "engOutputBuffer");
   Matlab_Output: aliased Interfaces.C.Char_Array(1..50000);
begin
   EngOutputBuffer (To_Chars_Ptr(Matlab_Output'Access));
end Test_Access;
------------------- End Code Segment ---------------------

A compilation failed with these messages:
   Warning: aliased object has explicit bounds
   Warning: declare with explicit initialization
   Warning: for use with unconstrained access
   Object subtype must statically match designated subtype

Could you help me get into the Interfaces.C... spirit?

Thanks,





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

* Re: HELP: Interfaces.C...
  2000-04-06  0:00 HELP: Interfaces.C Jack W. Sharer
@ 2000-04-11  0:00 ` Tucker Taft
  0 siblings, 0 replies; 2+ messages in thread
From: Tucker Taft @ 2000-04-11  0:00 UTC (permalink / raw)


"Jack W. Sharer" wrote:
> ...
> While this code works, the form of the first and second
> arguments appear to go against the spirit of the
> Interfaces.C... packages.

I think your first solution is fine.  Using 'Access to pass
array parameters should be a last resort.  It is used by
some automatic binding generators, because they don't know
whether a given pointer argument in C is really an IN, IN OUT, or
OUT parameter.  Since you are creating this binding by hand,
use all the information you can to minimize the use of access
types.

> ...
> Could you help me get into the Interfaces.C... spirit?

Stick with your first solution.  It was in the "Ada" spirit,
which is more important, IMHO.  Furthermore, it works!

> 
> Thanks,

-- 
-Tucker Taft   stt@averstar.com   http://www.averstar.com/~stt/
Technical Director, Distributed IT Solutions  (www.averstar.com/tools)
AverStar (formerly Intermetrics, Inc.)   Burlington, MA  USA




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

end of thread, other threads:[~2000-04-11  0:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-04-06  0:00 HELP: Interfaces.C Jack W. Sharer
2000-04-11  0:00 ` Tucker Taft

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