comp.lang.ada
 help / color / mirror / Atom feed
From: Rob Norris <firstname.lastname@baesystems.com>
Subject: Re: Ada array vs C pointer (call by reference)
Date: Thu, 03 Jul 2008 13:44:08 +0100
Date: 2008-07-03T13:44:08+01:00	[thread overview]
Message-ID: <bvhp64hd6qq6q3q1t8qrebjcdh5mfq11ib@4ax.com> (raw)
In-Reply-To: wccy74qke38.fsf@shell01.TheWorld.com

On Fri, 27 Jun 2008 13:00:27 -0400, Robert A Duff <bobduff@shell01.TheWorld.com> wrote:

>Keith Thompson <kst-u@mib.org> 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.



  parent reply	other threads:[~2008-07-03 12:44 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-06-27  1:39 Ada array vs C pointer (call by reference) Adrian Hoe
2008-06-27  1:42 ` Adrian Hoe
2008-06-27  2:55 ` Adam Beneschan
2008-06-27 13:02   ` Maciej Sobczak
2008-06-27 13:15     ` Adrian Hoe
2008-06-27 14:43     ` Georg Bauhaus
2008-06-27 14:47       ` Georg Bauhaus
2008-06-27 20:35       ` Maciej Sobczak
2008-06-27 22:00         ` Georg Bauhaus
2008-06-27 22:46           ` Keith Thompson
2008-06-27 16:11     ` Keith Thompson
2008-06-27 17:00       ` Robert A Duff
2008-06-27 18:15         ` Keith Thompson
2008-06-28 14:02         ` Stephen Leake
2008-06-28 21:18           ` Keith Thompson
2008-07-03 12:44         ` Rob Norris [this message]
2008-06-27 20:44       ` Maciej Sobczak
2008-06-27 22:14         ` Keith Thompson
2008-06-27 22:36           ` Adam Beneschan
2008-06-28 14:04             ` Stephen Leake
2008-06-28 21:22               ` Keith Thompson
2008-06-30 17:13               ` Adam Beneschan
2008-06-28 17:52             ` Robert A Duff
2008-06-30 17:13               ` Adam Beneschan
2008-06-30 18:55                 ` Robert A Duff
2008-07-01 21:19                 ` Randy Brukardt
2008-07-01 21:19                 ` Randy Brukardt
2008-06-28  0:56         ` Peter C. Chapin
2008-06-28 14:11           ` Maciej Sobczak
2008-06-28 17:49             ` tmoran
2008-06-28 21:46             ` Keith Thompson
2008-06-28 17:44         ` Robert A Duff
2008-07-01 21:10       ` Randy Brukardt
2008-06-27 18:13     ` tmoran
2008-06-27 20:49       ` Maciej Sobczak
2008-06-27  4:10 ` Jeffrey R. Carter
2008-06-27  8:22   ` Adrian Hoe
2008-06-27 15:07     ` Adam Beneschan
2008-06-27 22:54     ` Jeffrey R. Carter
2008-06-28  1:15       ` Adrian Hoe
2008-06-28  2:17         ` Adam Beneschan
2008-07-01 21:31           ` Randy Brukardt
2008-07-01 21:31           ` Randy Brukardt
2008-08-22  4:06           ` Adrian Hoe
2008-06-28  4:59         ` Jeffrey R. Carter
2008-06-29  3:48         ` anon
2008-06-28  1:21 ` anon
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox