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,8ecbc35ea893182f X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!t66g2000hsf.googlegroups.com!not-for-mail From: Maciej Sobczak Newsgroups: comp.lang.ada Subject: Re: Interfacing to C: big structures Date: Wed, 27 Feb 2008 05:49:43 -0800 (PST) Organization: http://groups.google.com Message-ID: <3709c993-cfb6-4752-9d9f-2450512a820c@t66g2000hsf.googlegroups.com> References: <62idb0F23ddfnU1@mid.individual.net> <56a177e4-506f-4bc8-a531-7f2dd15d50c8@i7g2000prf.googlegroups.com> NNTP-Posting-Host: 85.3.255.124 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: posting.google.com 1204120184 4421 127.0.0.1 (27 Feb 2008 13:49:44 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Wed, 27 Feb 2008 13:49:44 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: t66g2000hsf.googlegroups.com; posting-host=85.3.255.124; posting-account=bMuEOQoAAACUUr_ghL3RBIi5neBZ5w_S User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1.12) Gecko/20080201 Firefox/2.0.0.12,gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:20126 Date: 2008-02-27T05:49:43-08:00 List-Id: On 27 Lut, 02:37, Robert A Duff wrote: > I think Maciej is trying to avoid heap allocation, because then you have > to worry about deallocation. This might not be the only reason. Another one might be to fulfill the constraints of high-integrity system. > But dynamic-sized allocation on the stack > should be OK in that regard. If you don't like the dynamic size (it > does introduce some inefficiency), then you could do this: > > S_Size : constant := 24; -- or whatever you know it is > pragma Assert (S_Size = Size_Of_S); > type S is new Ada.Streams.Stream_Element_Array (1 .. S_Size); > for S'Alignment use ...; Yes, this is one of the possibilities. It can be improved with a script that is executed at build time that gets the sizeof(S) in C and copies it verbatim to the Ada source file (it can be a separate source file for exactly this purpose). This way both consistency and compile-time "constness" can be achieved. Such a script can be actually part of some bigger activity that gathers system-specific information. See autotools for example. -- Maciej Sobczak * www.msobczak.com * www.inspirel.com