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,5a84d5077c54a29d X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!news2.google.com!news.glorb.com!news-peer-lilac.gradwell.net!not-for-mail From: Rob Norris Newsgroups: comp.lang.ada Subject: Re: Ada array vs C pointer (call by reference) Date: Thu, 03 Jul 2008 13:44:08 +0100 Message-ID: References: <5df91e99-a972-48f7-b466-3eb05dc0a915@m3g2000hsc.googlegroups.com> X-Newsreader: Forte Free Agent 3.3/32.846 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Original-NNTP-Posting-Host: glkas0286.greenlnk.net NNTP-Posting-Host: 20.133.0.1 X-Trace: 1215089056 news.gradwell.net 78072 dnews/20.133.0.1:37545 X-Complaints-To: news-abuse@gradwell.net Xref: g2news1.google.com comp.lang.ada:991 Date: 2008-07-03T13:44:08+01:00 List-Id: On Fri, 27 Jun 2008 13:00:27 -0400, Robert A Duff wrote: >Keith Thompson writes: > >> Interfaces.C.C_Float, which (assuming the Ada implementation gets it >> right), is guaranteed to match C's float, or of using Float, which has >> no such guarantee (but saves a little typing). Why would you even >> consider using Float? > >You might have a program that uses Float all over the place, >and you want to add some interface to C in one tiny corner >of that program. You might be tempted to use Float at the >interface to C in order to avoid a lot of type conversions. > >It's a pretty good bet that Ada's Float and Ada's Interfaces.C.C_Float, >and C's float are all represented the same. If you're using GNAT, >I think the documentation guarantees that. > >But you're right -- the "right" way to interface to C is to use the >types in Interfaces.C, and use pragma Convention when you declare >your own types. > >- Bob Not too sure where to put my 2p in this thread, but the 'right' way certainly works much better at run time! We have plenty of code that maps between Ada and C, some of it GNAT and gcc (but different versions on different platforms) and also Ada and C#. Every so often some one forgets and slips in an Ada float or integer in the data structures. Then at runtime it either get strange results / constriant errors / crashes. Then I come to have a look and go Aha - you should be using Interfaces.C - and these problems go away* *Except for all the weird alignment issues of records / structures different compilers sometime give.