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!news4.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:28:48 -0500 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: <62idb0F23ddfnU1@mid.individual.net> <62ip0mF23cobbU1@mid.individual.net> <62iskrF23lre0U1@mid.individual.net> NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: pcls6.std.com 1204075730 6634 192.74.137.71 (27 Feb 2008 01:28:50 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Wed, 27 Feb 2008 01:28:50 +0000 (UTC) User-Agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.3 (irix) Cancel-Lock: sha1:DPnvsEi5mMWe1XFSeglwWTACPRM= Xref: g2news1.google.com comp.lang.ada:20116 Date: 2008-02-26T20:28:48-05:00 List-Id: "Alex R. Mosteo" writes: > I see. So, for example, let's say there's this C function: > > void init (struct S *s) {...}; > > and you pass the Ada array address to it. > > It may crash/ill-behave, if the C code takes for granted that the s > pointer is, say, 8-aligned, and some C generated code within "init" > depends on this assumption. > > It may be slow, otherwise, if no such assumption exists. Right. The crash vs. slow issue is defined by the hardware, in practise. x86 machines tolerate unaligned refs (slowly) whereas RISC machines tend to trap on unaligned refs. > I'm missing some other possibilities? No, I don't think you're missing anything. > And, finally, is adding an alignment clause enough to solve this issue? > If so, how do you query the alignment of a C datatype? I'm not a C expert, but I don't think there's any easy way. > (Could a conservative approach be to force the Ada side type to be > max-aligned for the architecture?) Yes. Probably "for S'Alignment use Long_Float'Alignment" will work OK on most machines. Is there a cleaner way to do that? - Bob