comp.lang.ada
 help / color / mirror / Atom feed
From: Adam Beneschan <adam@irvine.com>
Subject: Re: Possible compiler bug with this simple program
Date: Thu, 28 Aug 2008 08:54:15 -0700 (PDT)
Date: 2008-08-28T08:54:15-07:00	[thread overview]
Message-ID: <e203303d-0f2d-4779-9459-952dca31b0e1@w24g2000prd.googlegroups.com> (raw)
In-Reply-To: 48b65b3b$0$25384$4f793bc4@news.tdc.fi

On Aug 28, 1:03 am, Niklas Holsti <niklas.hol...@tidorum.invalid>
wrote:

> In fact, when an Ada subprogram has an unconstrained array
> parameter with Convention C, it seems to me that the subprogram's
> body cannot make any use of individual elements of the array,
> because it doesn't know the index range, so the compiler should
> reject any indexing of such an array parameter, as well as any
> attempt to pass it on as a Convention Ada parameter.

Yes, good point.  For an unconstrained array parameter like X, the
compiler doesn't need to know what X'Last is in order to access
elements of the array---but it does need to know X'First.  (X'Last is
needed for range checking but not for actually accessing elements.)
If you're using strictly Ada, with no Convention parameters or
anything, then when mapform19 is called, the caller somehow has to
make X'First and X'Last available to the routine, and then when X(I)
is accessed, the generated code must compute I - X'First, multiply
that by the element size, and add the result to the address of X's
data.  When mapform19 is called from a C routine, nothing will be
passed in for X'First, but mapform19 will still try to subtract
something from I, and what value it will subtract is quite random---
could be zero, could be some other garbage value.

I agree that the compiler should have rejected this.  But it might
work to declare Real_Vector as a constrained array:

   type Real_Vector is array (0 .. Integer'Last) of Long_Float;

Now the compiler will know that X'First is 0 and, hopefully, behave
correctly.

                              -- Adam




  reply	other threads:[~2008-08-28 15:54 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 [this message]
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
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