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.fn3LatRFkm9/xzEj7F2/NQ.user.gioia.aioe.org!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: How to bind this properly, C ** which is an array Date: Fri, 1 Mar 2019 15:02:48 +0100 Organization: Aioe.org NNTP Server Message-ID: References: <1bb2318a-eb48-450f-908d-a304b92bd74c@googlegroups.com> NNTP-Posting-Host: fn3LatRFkm9/xzEj7F2/NQ.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.5.1 X-Notice: Filtered by postfilter v. 0.9.2 Content-Language: en-US Xref: reader01.eternal-september.org comp.lang.ada:55739 Date: 2019-03-01T15:02:48+01:00 List-Id: On 2019-03-01 14:48, Lucretia wrote: > Hi, > > I'm trying to bind the following struct: > > typedef struct mpc_ast_t { > char *tag; > char *contents; > mpc_state_t state; > int children_num; > struct mpc_ast_t** children; > } mpc_ast_t; > > I have this: > > type ASTs is > record > Tag : C.Strings.chars_ptr; > Contents : C.Strings.chars_ptr; > State : States; > Number_Of_Children : C.int; > Children : System.Address; -- Pointer to a pointer to an array of ASTs. > end record with > Convention => C; > > Children needs to be accessed in code as a pointer to a pointer to an array of ASTs. > > How do I best bind this thing? It's likely going to have to be converted from Address to a particular type using Unchecked_Conversion most likely. I think you could do it without Unchecked_Conversion: -- Forward declaration type ASTs; type ASTs_Ptr is access all ASTs; pragma Convention (C, ASTs_Ptr); -- Flat array of pointers without bounds type ASTs_Ptr_Array is array (size_t) of ASTs_Ptr; pragma Convention (C, ASTs_Ptr_Array); type ASTs_Ptr_Array_Ptr is access all ASTs_Ptr_Array; pragma Convention (C, ASTs_Ptr_Array_Ptr); -- Now the type type ASTs is record Tag : C.Strings.chars_ptr; Contents : C.Strings.chars_ptr; State : States; Number_Of_Children : C.int; Children : ASTs_Ptr_Array_Ptr; end record; pragma Convention (C, ASTs); -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de