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,594935f0c2f19bc4 X-Google-Attributes: gid103376,public From: nobody@REPLAY.COM (Anonymous) Subject: Re: how to pass access string across pragma C interface? Date: 1997/06/20 Message-ID: <199706201302.PAA27925@basement.replay.com>#1/1 X-Deja-AN: 251327579 References: <866734587.8496@dejanews.com> Organization: Replay and Company UnLimited X-001: Replay may or may not approve of the content of this posting Mail-To-News-Contact: postmaster@nym.alias.net X-002: Report misuse of this automated service to X-URL: http://www.replay.com/remailer/ Newsgroups: comp.lang.ada Date: 1997-06-20T00:00:00+00:00 List-Id: On Thu, 19 Jun 1997 10:41:08 -0600, burch@cyberhighway.net wrote: > I'm using Ada83 with the Alsys compiler and I'm having problems getting > access strings to pass to C char* across the pragma interface call. What > kind of type definitions does one have to do on the Ada side to get the > types to match up? This is what I've done so far, which gives a > constraint error on run time. > type string_access_type is access string( 1 ..2048); > > function read_func ( > socket_fd : in integer; > buffer : in string_access_type > ) return integer; > pragma interface ( C , read_func ); > pragma interface_name( read_func, "read" ); > > . > . > . > begin > > > . > . > status_read := read_func ( socket_fd, buffer ); > > the C function "read" is > > int read (int, char*); > > What I'm trying to accomplish is to have "buffer" passed by reference to > C. C will go out and get the string from a socket, return, and > (hopefully) I'll be able to use it back on the Ada side. > > I'm new with with Ada, so any comments for my learning would be > appreciated. Thank you in advance. In Ada 83, you have to define the function as accepting an address: Buffer : String (1 .. 2048); .. function Read (Socket : Integer; Buffer : System.Address) return Integer; pragma Interface (C, Read); .. Result := Read (Socket, Buffer (1)'Address); In Ada (Ada 95, ISO/IEC 8652:1995), you can use an access parameter: subtype Buffer_String is String (1 .. 2048); Buffer : aliased Buffer_String; .. function Read (Socket : Integer; Buffer : access Buffer_String) return Integer; pragma Import (C, Read); .. Result := Read (Socket, Buffer'access); Jeff Carter PGP:1024/440FBE21 My real e-mail address: ( carter @ innocon . com ) "Now go away, or I shall taunt you a second time." Monty Python & the Holy Grail Posted with Spam Hater - see http://www.compulink.co.uk/~net-services/spam/