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=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!feeder.eternal-september.org!aioe.org!.POSTED.3d73Ybk3C5U4I2t8lv+lAQ.user.gioia.aioe.org!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Is this actually possible? Date: Wed, 11 Dec 2019 18:38:34 +0100 Organization: Aioe.org NNTP Server Message-ID: References: <36d45c82-2a6b-4c60-baeb-1a4aef5189c7@googlegroups.com> NNTP-Posting-Host: 3d73Ybk3C5U4I2t8lv+lAQ.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.9.1 X-Notice: Filtered by postfilter v. 0.9.2 Content-Language: en-US Xref: reader01.eternal-september.org comp.lang.ada:57706 Date: 2019-12-11T18:38:34+01:00 List-Id: On 2019-12-11 17:43, Lucretia wrote: > I was thinking about extensible records recently (not tagged types), and thought to try to export a tagged type to C, not C++. It compiles, but the results aren't quite right, so wondering if it's possible or not. > > The idea is to export an array of tagged types as a C array to either a function or a variable / struct element. i.e. Ada objects of tagged types have varying size and keep tag inside. Both make them utterly incompatible with C. > type Storage_Array is array (Positive range <>) of Storage_Element with > Convention => C; This type cannot be used with C because an object of will have bounds inside. If you need an array compatible with C, it must a "flat" array: type C_Storage_Array is array (size_t) of Storage_Element; Naturally you will never declare such objects in your program. You will get them from C or allocate raw memory and then having the address of the first element do: A : C_Storage_Array; pragma Import (Ada, A); for A'Address use The_Address_Of_A; It is your responsibility not to index it outside the bounds. Just like in C. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de