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=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,1b043921d2cf45d2 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!postnews.google.com!k36g2000pri.googlegroups.com!not-for-mail From: Maciej Sobczak Newsgroups: comp.lang.ada Subject: Re: Interfacing to C without dynamic memory Date: Sun, 16 Nov 2008 13:31:14 -0800 (PST) Organization: http://groups.google.com Message-ID: <088082af-1fa9-4636-a7e2-39731aa9a6be@k36g2000pri.googlegroups.com> References: <8a0e9a41-6670-486b-bbb7-7ef706643930@a17g2000prm.googlegroups.com> <87bpwhurxl.fsf@willow.rfc1149.net> NNTP-Posting-Host: 85.3.80.4 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1226871075 6527 127.0.0.1 (16 Nov 2008 21:31:15 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Sun, 16 Nov 2008 21:31:15 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: k36g2000pri.googlegroups.com; posting-host=85.3.80.4; posting-account=bMuEOQoAAACUUr_ghL3RBIi5neBZ5w_S User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.0.3) Gecko/2008092414 Firefox/3.0.3,gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:2691 Date: 2008-11-16T13:31:14-08:00 List-Id: On 15 Lis, 12:52, Samuel Tardieu wrote: > Note that you can also do it at run time, even if it costs a few more > cycles to allocate the object, by taking advantage of C ability to > resolve "sizeof" into a static value at compile time. This obliviates > the cross-compilation issues. > const size_t T_size =3D sizeof(struct T); > =A0 =A0T_Size : constant Interfaces.C.size_t; > =A0 =A0pragma Import (C, T_Size, "T_size"); Neat. This possibility was not obvious to me. > =A0 =A0type Opaque_T is new Interfaces.C.char_array (1 .. T_Size); > =A0 =A0for Opaque_T'Alignment use 8; Of course, I can similarly extract the magic 8 constant from the C file (sizeof(long long) or such). Two more questions: 1. Any technical difference between System.Storage_Array and Interfaces.C.char_array? Considering that the target module is C, using the latter is more logical, but apart from "name affinity" is there anything that can make a difference in practice? 2. Now the array has run-time size instead of compile-time size (as you mentioned yourself). Is there any difference, especially in terms of memory management? Are such arrays guaranteed to be allocated on the stack? -- Maciej Sobczak * www.msobczak.com * www.inspirel.com Database Access Library for Ada: www.inspirel.com/soci-ada