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-Thread: 103376,8ecbc35ea893182f X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news2.google.com!news.glorb.com!newscon02.news.prodigy.net!prodigy.net!newsfeed-00.mathworks.com!nntp.TheWorld.com!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: Interfacing to C: big structures Date: Tue, 26 Feb 2008 20:37:17 -0500 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: <62idb0F23ddfnU1@mid.individual.net> <56a177e4-506f-4bc8-a531-7f2dd15d50c8@i7g2000prf.googlegroups.com> NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: pcls6.std.com 1204076239 17143 192.74.137.71 (27 Feb 2008 01:37:19 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Wed, 27 Feb 2008 01:37:19 +0000 (UTC) User-Agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.3 (irix) Cancel-Lock: sha1:9gJ1fRNHGsaKq4p67luCy5OodLE= Xref: g2news1.google.com comp.lang.ada:20117 Date: 2008-02-26T20:37:17-05:00 List-Id: Adam Beneschan writes: > I thought of something like this, but Maciej said something about > wanting to avoid dynamic memory,... I think Maciej is trying to avoid heap allocation, because then you have to worry about deallocation. 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 ...; Now the Ada compiler knows the right size statically. If the C code changes, you have to change 24 to something else, but at least you get notified to do so (the simplest testing will fail on the Assert). - Bob