Re: Possible compiler bug with this simple program
- From: Adam Beneschan <adam@xxxxxxxxxx>
- Date: Thu, 28 Aug 2008 08:54:15 -0700 (PDT)
On Aug 28, 1:03 am, Niklas Holsti <niklas.hol...@xxxxxxxxxxxxxxx>
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
.
- Follow-Ups:
- Re: Possible compiler bug with this simple program
- From: Adam Beneschan
- Re: Possible compiler bug with this simple program
- References:
- Possible compiler bug with this simple program
- From: Jerry
- Re: Possible compiler bug with this simple program
- From: Niklas Holsti
- Possible compiler bug with this simple program
- Prev by Date: Re: OpenToken (was: Status of ayacc and aflex?)
- Next by Date: Re: Possible compiler bug with this simple program
- Previous by thread: Re: Possible compiler bug with this simple program
- Next by thread: Re: Possible compiler bug with this simple program
- Index(es):
Relevant Pages
|