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=0.2 required=5.0 tests=BAYES_00,INVALID_MSGID, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,8da8963fe574ea15 X-Google-Attributes: gid103376,public From: Jeff Carter Subject: Re: Newbie question about interface to C Date: 2000/05/31 Message-ID: <3935852C.F801DF4F@acm.org>#1/1 X-Deja-AN: 629647574 Content-Transfer-Encoding: 7bit References: X-Accept-Language: en Content-Type: text/plain; charset=us-ascii X-Complaints-To: abuse@earthlink.net X-Trace: newsread2.prod.itd.earthlink.net 959812477 63.10.53.229 (Wed, 31 May 2000 15:34:37 PDT) Organization: EarthLink Inc. -- http://www.EarthLink.net MIME-Version: 1.0 Reply-To: jrcarter@acm.org NNTP-Posting-Date: Wed, 31 May 2000 15:34:37 PDT Newsgroups: comp.lang.ada Date: 2000-05-31T00:00:00+00:00 List-Id: David Gressett wrote: > > I need to call C routines which are prototyped like these examples: > > shapelessblob *somefunction(char *s); /* creates a shaplessblob */ > > int otherfunction(shapelessblob *b); /* uses a shaplessblob */ > > where shaplessblob is a pointer to a structure that is created by > somefunction. The calling Ada code will never look at the insides of a > shapelessblob; It will only pass it to a C routine. > > How do I import such a pointer as an Ada access type? This cannot be answered completely without knowing how the functions deal with their parameters. Do they use the initial value? Do they modify them? For example, if the char* parameter s to somefunction is used for input only (Ada mode in), then you could declare the function as taking an Interfaces.C.char_array; pragma Import will perform the necessary gymnastics to pass a char* to the C. As for type shapelessblob*, you could probably get by with System.Address since you don't care what it points to. To be safe, though, you should do something like type C_Struct is record I : Interfaces.C.Int; end record; pragma Convention (C, C_Struct); type Shapeless_Blob is access all C_Struct; pragma Convention (C, Shapeless_Blob); and use Shapeless_Blob for shapelessblob*. -- Jeff Carter "Hello! Smelly English K...niggets." Monty Python & the Holy Grail