comp.lang.ada
 help / color / mirror / Atom feed
From: Keith Thompson <kst-u@mib.org>
Subject: Re: Ada array vs C pointer (call by reference)
Date: 27 Jun 2008 15:14:19 -0700
Date: 2008-06-27T15:14:19-07:00	[thread overview]
Message-ID: <lzwska8r0k.fsf@stalkings.ghoti.net> (raw)
In-Reply-To: 3dcc4a2d-f2f9-4c98-96c8-cd9dd1b090fe@z72g2000hsb.googlegroups.com

Maciej Sobczak <see.my.homepage@gmail.com> writes:
> On 27 Cze, 18:11, Keith Thompson <ks...@mib.org> wrote:
> > > Ada *cannot* guarantee that Interfaces.C.C_Float is the *right* float,
> > > because it does not verify how the C code was compiled and there is a
> > > lot of freedom given to C implementers in this area.
> > > Same for all other types.
> >
> > No, Ada can't guarantee it directly.  Instead, Ada requires the
> > implementation to guarantee it.
> 
> And how the implementation can guarantee it without mandating the
> representation on the C compiler?

It doesn't *mandate* the representation used by the C compiler; the
author of the Interfaces.C implementation has to *know* the
representation used by the C compiler.

And yes, the fact that different C compilers on the same system might
use different representations is an issue.

> Consider a C compiler that has a switch that selects the
> representation for fundamental types. It is not uncommon.
> I can have *the same* program compiled twice by *the same* compiler
> and the two versions will differ in representation of their
> fundamental types.
> 
> How Ada implementation can guarantee anything in this area?

The C compiler invoked with the switch and the same compiler invoked
without the switch are logically two different C implementations.

The Ada compiler, if it wants to support both of them, might provide
two distinct Interfaces.* subpackages, say Interfaces.C_Foo and
Interfaces.C_Bar.

It's an imperfect solution, but no perfect solution is possible.

> > Look at it this way.  You have the choice of using
> > Interfaces.C.C_Float, which (assuming the Ada implementation gets it
> > right), is guaranteed to match C's float
> 
> There is no way to guarantee that. The only way is to name two
> compilers and say that *they* are compatible with this and that
> switches. But then - there is no added value from Interfaces.C.XXX.

I disagree.  The developers of the particular implementation of
Interfaces.C have done the work of figuring out the characteristics of
the particular C implementation, so you don't have to.

> > Why would you even
> > consider using Float?
> 
> Because the amount of magic and handwaving in interfacing is the same
> as with Interfaces.C.C_float, but it is less typing. :-)

If you use Interfaces.C.C_float and it doesn't work, you can complain
to your Ada compiler vendor, who just might have a solution that's
better than anything you or I have thought of.

The bottom line is that there's no fundamental reason to assume that
Ada's Float and C's float have the same representation, or that an Ada
compiler should necessarily follow a C compiler's decisions regarding
type representations.  Though there's nothing wrong with doing so if
it happens to be convenient, as it is in the case of GNAT.

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
Nokia
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"



  reply	other threads:[~2008-06-27 22:14 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
2008-06-27 20:44       ` Maciej Sobczak
2008-06-27 22:14         ` Keith Thompson [this message]
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