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,91c8a2ba0b435b28 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-03-17 12:09:36 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!news-out.visi.com!petbe.visi.com!uunet!ash.uu.net!nntp.TheWorld.com!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: Interfacing Generics with C Pointers Date: 17 Mar 2003 15:09:34 -0500 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: pcls4.std.com 1047931774 18872 199.172.62.241 (17 Mar 2003 20:09:34 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Mon, 17 Mar 2003 20:09:34 +0000 (UTC) User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 Xref: archiver1.google.com comp.lang.ada:35421 Date: 2003-03-17T15:09:34-05:00 List-Id: Brian Palmer writes: > I've got a problem where I get in a pointer to a block of memory that was > allocated in C++. In addition to the pointer, I get the number of bytes > that were allocated. The Ada type that the memory comes in as is a pointer > to an unconstrained byte array. Whenever I try to dereference the pointer, > I get a CONSTRAINT ERROR. I think the problem is due to the compiler > trying to access a storage location within the type that tells how many > bytes are there. Probably true. In general, unconstrained arrays don't work well when interfacing to C, because C doesn't know about the dope. >... I feel like I could constrain the base type and get > around the problem, however, this mechanism is used for several different > size blocks of memory, several hundred times per second, and I don't want > to have to allocate more memory than necessary. Any ideas how to access > unconstrained memory without the compiler looking for that built in > element? One way is to lie to the Ada compiler about the length of the array. E.g., "type T is array(Natural) of ...;" then you get back a pointer to T, and you can refer to X.all(I). Just make sure I doesn't go out of the "real" ounds. Presumably the real bounds are available via some other means. As soon as possible, start dealing with the data in a safer way -- e.g., pass the appropriate slice of X.all off the to rest of the code. - Bob