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=3.8 required=5.0 tests=BAYES_00,INVALID_MSGID, RATWARE_MS_HASH,RATWARE_OUTLOOK_NONAME 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: "David C. Hoos, Sr." Subject: Re: how to pass access string across pragma C interface? Date: 1997/06/22 Message-ID: <01bc7f0c$494ab860$428371a5@dhoossr.iquest.com>#1/1 X-Deja-AN: 251774308 Distribution: world References: <866734587.8496@dejanews.com> Organization: Ada95 Press, Inc. Newsgroups: comp.lang.ada Date: 1997-06-22T00:00:00+00:00 List-Id: Hi Tim, Hour code does not show the declaration of "buffer": used in the call to "read", so it is possible that there is a problem associated with that. Since I am not familiar with your compiler (you didn't specify a platform), my remarks have certain underlying assumptions which I will specify. Assuming that the bit pattern for an access value and a C pointer are identical on your platform (this assumption is implicit in your interface pragma), then you should do something like: buffer : string_access_type := new string (1 .. 2048); My own preference for doing this sort of thing is not to use dynamic memory, but instead to specify the Ada System.Address type for parameters corresponding to C pointers. Then I use a variable declaration such as Buffer:string (1 . 2048), and call the procedure with buffer'address for the System.Address parameter. This has the advantage of not tying your declaration of "read" to a specific buffer size. Of course, you need to use the ststus_read value to determine how many bytes were returned. If the value returned was --1, then you need to look at the errno value to determine what went wrong. For example, if the errno value is EINTR, you would know that the read was interrupted, and that you should increment the address value by that many bytes and call read again (another reason for making the C pointer equivalent a System.Address value instead of an access value).. One final thing puzzles me. Usually read functions like this have another integer parameter -- i.e., the number of bytes to read. Hope all this helps. -- David C. Hoos, Sr., http://www.dbhwww.com http://www.ada95.com burch@cyberhighway.net wrote in article <866734587.8496@dejanews.com>... > 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. > > Tim Burch > burch@cyberhighway.net > > -------------------==== Posted via Deja News ====----------------------- > http://www.dejanews.com/ Search, Read, Post to Usenet >