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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,6b77ce1ba18f9267 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-01-09 19:50:06 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!canoe.uoregon.edu!arclight.uoregon.edu!newsfeed.mathworks.com!cyclone.swbell.net!newsfeed1.easynews.com!easynews.com!easynews!newsfeed1.earthlink.net!newsfeed.earthlink.net!stamper.news.pas.earthlink.net!newsread1.prod.itd.earthlink.net.POSTED!not-for-mail From: "Eric G. Miller" User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2.1) Gecko/20021226 Debian/1.2.1-9 MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Import a type from C References: In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Message-ID: Date: Fri, 10 Jan 2003 03:48:48 GMT NNTP-Posting-Host: 216.119.14.19 X-Complaints-To: abuse@earthlink.net X-Trace: newsread1.prod.itd.earthlink.net 1042170528 216.119.14.19 (Thu, 09 Jan 2003 19:48:48 PST) NNTP-Posting-Date: Thu, 09 Jan 2003 19:48:48 PST Organization: EarthLink Inc. -- http://www.EarthLink.net Xref: archiver1.google.com comp.lang.ada:32853 Date: 2003-01-10T03:48:48+00:00 List-Id: Rupert Pigott wrote: > "Stephen Leake" wrote in message > news:u7kfqjnvv.fsf@gsfc.nasa.gov... > >>"Frank J. Lhota" writes: >> >> >>> pragma Convention( C, My_Data ); >>> >>>The Convention pragma can be used to specify that this record type > > should be > >>>laid out in the same way that a C compiler would. >> >>Note that "a C compiler" really means "the C compiler that the Ada >>compiler knows about, with its default command line args". For >>example, GNAT will assume Gnu C, _without_ -fpacked. ObjectAda >>probably assumes MS C, again without the "packed" flag. That has >>caused me some major problems, when linking against C code compiled >>_with_ the -fpacked flag. >> >>So I always use a rep spec, instead of relying on Convention (C). Then >>I write some C code that checks the struct size, to be sure there is >>no padding. > > > Perhaps I'm overly pessimistic here... IIRC there is no guarantee > of the order of members within a structure in C either. One of those > little gotchas (along with no alignment control) that **** portable > code and force you to go the long way around... You're high 8^) The order of members in a C struct is always as specified in the definition. Furthermore, a pointer to a struct is always guaranteed to resolve to a pointer to the first member. The alignment of any subsequent members is implementation defined. Portable C code would never pack a struct to begin with (an inherently unportable practice). -- echo ">gra.fcw@2ztr< eryyvZ .T pveR" | rot13 | reverse