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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,4947e94bd021c540 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-10-07 11:30:59 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!headwall.stanford.edu!newshub.sdsu.edu!elnk-nf2-pas!newsfeed.earthlink.net!wn14feed!wn13feed!wn11feed!worldnet.att.net!204.127.198.203!attbi_feed3!attbi_feed4!attbi.com!rwcrnsc51.ops.asp.att.net.POSTED!not-for-mail From: tmoran@acm.org Newsgroups: comp.lang.ada Subject: Re: C array to Ada pointer to unconstrained array without copying memory References: X-Newsreader: Tom's custom newsreader Message-ID: NNTP-Posting-Host: 12.234.124.41 X-Complaints-To: abuse@comcast.net X-Trace: rwcrnsc51.ops.asp.att.net 1065551456 12.234.124.41 (Tue, 07 Oct 2003 18:30:56 GMT) NNTP-Posting-Date: Tue, 07 Oct 2003 18:30:56 GMT Organization: Comcast Online Date: Tue, 07 Oct 2003 18:30:56 GMT Xref: archiver1.google.com comp.lang.ada:388 Date: 2003-10-07T18:30:56+00:00 List-Id: >subtype Array2 is Ada_Array (1 .. Length); > >X : Array2; >for X'Address use Ptr; -- ok, Ptr should be of type System'Address, but hey! > >And then you can make use of X. However being defined on the stack, it >can be quite awkward to use. I don't understand. Nothing is defined on, or off, the stack here. You are saying that X is at location 12345 (or whatever) in RAM. Whether X happens to be in the same area as the stack depends on whether (System.Address_to_Access_Conversions .To_Address of) Ptr happens to point into the stack or not. >It would be nice to have the same thing but with X dynamically allocated. If Ptr points into your program's heap memory, that's where X will be. Or do you mean C is allocating memory, and setting its memory allocation structures, and you want an Ada Access type, and Ada's memory allocation structures, to be set as if that memory was allocated by an Ada "new"? >The problem is the bounds of course. If a call to C gave you an address and a length, then those, not a constrained array, are what you have to work with. Just as in C, you'll have to write things like if Index in 1 .. Length then Y := X(Index); else raise Constraint_Error; end if; >For example, GNAT usually uses >fat pointers, consisting of two normal pointers where one points to the >data, and the other to the bounds. So the "clever stuff" will need to >allocate some memory to hold the bounds and set up the fat pointer >appropriately. So you're talking about using embedded assembly language to fake out the compiler? If it's the only way to get to the moon, someone will have to put themselves on top of an enormous can of explosives and light the outlets. Most real problems, however, can be solved in less dangerous ways. What's the real problem you are trying to solve here?