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,af247e41be5f18ab X-Google-Attributes: gid103376,public From: dale@cs.rmit.edu.au (Dale Stanbrough) Subject: Re: simple question - how to emulate void * ? Date: 1998/11/06 Message-ID: #1/1 X-Deja-AN: 408855911 References: <9v6hGdgMLuwN-pn2-Oc41W71Dq3U9@dt182n2f.tampabay.rr.com> <9v6hGdgMLuwN-pn2-dpQX3EjC2po4@dt182n2f.tampabay.rr.com> X-Complaints-To: abuse@cs.rmit.edu.au X-Trace: emu.cs.rmit.edu.au 910312488 19981 144.205.16.58 (6 Nov 1998 00:34:48 GMT) Organization: Department of Computer Science, RMIT NNTP-Posting-Date: 6 Nov 1998 00:34:48 GMT Newsgroups: comp.lang.ada Date: 1998-11-06T00:34:48+00:00 List-Id: Craig Allen wrote: " I've tried the suggestions given here, and failed miserably. The culprit in all cases was the fact that I'm using an Ada83 compiler" Ah! This is a problem. I would then suggest that if you are trying to emulate void *, then continue to use System.Address. You should also create a mapping from System.Address to the appropriate pointer type by instantiating the Unchecked_Conversion function (which may not do it exactly - there is no 100% guarentee that a pointer is an address). It is likely that you will have more success if you use a pointer to a constrained type, as pointers to unconstrained types may well point at the descriptor, rather than the actual data. E.g. type My_String is array (1..100_000) of Character; -- any length will do, just ensure it's long enough for -- any problem you have to deal with. type Ptr is access My_String; function To_Ptr is new Unchecked_Conversion ( Source => System.Address, Target => Ptr); then... function Read_Bytes (...) return System.Address is begin blah blah blah; return Data'Address; end; X : Address := Read_Bytes (...); Y : Ptr := To_Ptr (Y); i : Positive := 1; Sentinel : constant Character := Ascii.nul; begin loop exit when Y (i) = Sentinel or i > My_String'Last; -- process item. i := i + 1; end loop; end; Of course you will have to customise Unchecked_Conversion to deal with any other pointer type. Using this will mean you get around any problems of the compiler expecting a static value for the address clause. Beware though - you are deliberately subverting the type system. Are you sure that this is necessary, or is there some aspect of the problem which would be more elegantly described _within_ the type system offered by Ada? Dale