From: Adam Beneschan <adam@irvine.com>
Subject: Re: Possible compiler bug with this simple program
Date: Fri, 5 Sep 2008 08:56:24 -0700 (PDT)
Date: 2008-09-05T08:56:24-07:00 [thread overview]
Message-ID: <51d75106-a44b-4c23-b612-b74dbae14fef@b30g2000prf.googlegroups.com> (raw)
In-Reply-To: 92e309c9-57d7-4a0b-8620-3320158ac0c3@a1g2000hsb.googlegroups.com
On Sep 5, 1:17 am, Ludovic Brenta <ludo...@ludovic-brenta.org> wrote:
> Jeff Carter writes:
> > Ada needs to know what the lower bound of this array parameter is, and
> > apparently your compiler is getting it wrong. Using a constrained array type
> > with a lower bound of zero and an upper bound as large or larger than can occur
> > would be the best choice for this situation.
>
> I would actually use a local, constrained array type of exactly the
> required length:
>
> procedure Ada_Callback (Length : in Natural; Array_Address : in
> System.Address);
> pragma Convention (C, Ada_Callback);
>
> procedure Ada_Callback (Length : in Natural; Array_Address : in
> System.Address) is
> type Constrained_Array_Subtype is array (1 .. Length) of
> Long_Float;
or array (0 .. Length - 1)...
> X : Constrained_Array_Subtype;
> for X'Address use Array_Address;
> pragma Import (Ada, X); -- disable default initialization
> begin
> ...
> end Ada_Callback;
>
> I know using System.Address may seem unholy at first sight but this
> implementation is explicit about what it does -- dangerous things with
> an address received from the unsafe "external world" outside the
> control of the compiler.
>
> Comments?
Doing it your way has a better chance of being portable. Earlier,
others and I have recommended using a constrained array subtype (with
a large upper bound) as a parameter, and I'd guess that will have the
desired effect on most compilers, but you never know---sometimes
compilers have unexpected ways of doing things. If you're sure that a
System.Address will look just like a C (void *) or (double *) type,
and will be passed in the same way, then using a System.Address
parameter will make pretty sure that things will work right.
-- Adam
next prev parent reply other threads:[~2008-09-05 15:56 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-08-28 7:28 Possible compiler bug with this simple program Jerry
2008-08-28 7:56 ` Ludovic Brenta
2008-08-28 21:08 ` Jerry
2008-08-29 20:39 ` Ludovic Brenta
2008-08-29 21:20 ` Jerry
2008-08-29 21:31 ` Jerry
2008-09-02 22:10 ` Santiago Urueña
2008-08-28 8:03 ` Niklas Holsti
2008-08-28 15:54 ` Adam Beneschan
2008-08-28 15:56 ` Adam Beneschan
2008-08-28 21:01 ` Randy Brukardt
2008-08-28 21:29 ` Jerry
2008-08-30 1:00 ` Randy Brukardt
2008-08-30 4:47 ` Jerry
2008-09-01 11:19 ` Jerry
2008-09-03 4:22 ` Jerry
2008-09-03 14:20 ` Adam Beneschan
2008-09-04 0:22 ` Jerry
2008-09-04 1:18 ` Adam Beneschan
2008-09-04 3:53 ` Randy Brukardt
2008-09-04 1:31 ` Jeffrey R. Carter
2008-09-04 14:35 ` Adam Beneschan
2008-09-04 14:42 ` Jacob Sparre Andersen
2008-09-06 3:03 ` Jerry
2008-09-05 8:17 ` Ludovic Brenta
2008-09-05 15:56 ` Adam Beneschan [this message]
2008-09-05 17:09 ` Jeffrey R. Carter
2008-09-04 20:49 ` Simon Wright
2008-08-28 21:16 ` Jerry
2008-08-29 7:41 ` Niklas Holsti
2008-08-30 0:50 ` Randy Brukardt
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox