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.4 required=5.0 tests=BAYES_00, GUARANTEED_100_PERCENT,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,e55ee29fd922b5bc X-Google-Attributes: gid103376,public From: Keith Thompson Subject: Re: Interfacing to void * Date: 1999/07/18 Message-ID: #1/1 X-Deja-AN: 502626785 References: <37929901.649C0955@worldnet.att.net> X-Complaints-To: usenet@nusku.cts.com X-Trace: nusku.cts.com 932367472 22328 198.68.168.21 (19 Jul 1999 06:57:52 GMT) Organization: CTS Network Services NNTP-Posting-Date: 19 Jul 1999 06:57:52 GMT Newsgroups: comp.lang.ada Date: 1999-07-19T06:57:52+00:00 List-Id: William Starner writes: > If I'm trying to interface to a C library that uses this struct > > struct BigNum { > void *ptr; > unsigned int size; > unsigned int allocated; > }; > > how should I interface to void*? > > I have > private > type voidpointer is access character; > type BigNum is record > ptr: voidpointer; > size: Interfaces.C.unsigned; > allocated: Interfaces.C.unsigned; > end record; > type RealBigNum is access BigNum; > type UnboundedInt is new Linear with record > Value: RealBigNum; > end record; > end nla23.linear.bnlib; > but char* = void* is a C rule, not an Ada rule. It probably works, > but it's not right. (I don't need to access anything through that > pointer.) You're not 100% guaranteed that an Ada type declared as "access Character" is compatible with a C "char*", or even that Ada's type Character is the same as C's char. My suggestion: type Void_Pointer is private; Null_Void_Pointer : constant Void_Pointer; ... type Void_Pointer is new Interfaces.C.Strings.chars_ptr; Null_Void_Pointer : constant Void_Pointer := Interfaces.C.Strings.Null_Ptr; By making it a private type, you avoid making the operations in Interfaces.C.Strings visible to clients. The closest semantic equivalent to C's void* is Ada's System.Address. This is *almost* certain to be compatible (I doubt that there's an existing system on which they're different), but the language doesn't guarantee it. -- Keith Thompson (The_Other_Keith) kst@cts.com San Diego Supercomputer Center <*> One of the great tragedies of ancient history is that Helen of Troy lived before the invention of the champagne bottle.