[Info-vax] Ada array initialisation, was: Re: OT: lightweight 90s viewer for Level 2 Postscript. Plus compiler-related obscureness.
Simon Clubley
clubley at remove_me.eisner.decus.org-Earth.UFP
Fri Aug 24 07:50:03 EDT 2012
On 2012-08-23, Simon Clubley <clubley at remove_me.eisner.decus.org-Earth.UFP> wrote:
> On 2012-08-23, John Wallace <johnwallace4 at gmail.com> wrote:
>>
>> What's the difference between an Ada array whose elements are
>> initialised using something like:
>> array_instance : [const?] array_type := (scalar_a'address,
>> scalar_b'address ...);
>> and an array initialised using the notation
>> array_instance : [const?] array_type := ( 1 => scalar_a'address, 2 =>
>> scalar_b'address);
>>
>> The correct answer, apparently, is that they are intended to be
>> equivalent, at least in the obvious case where every element in an
>> array with an integer index is initialised (or something like that).
>>
>
> Assuming the lower bound on the array is 1, then they should indeed
> be identical. The notation in the latter example is known as a "named
> aggregate" if you want to look it up.
>
>> However, two of us independently spotted at the same time today that
>> the two notations when fed into the older compiler generate different
>> initialisers. One notation correctly generates initialisers which at
>> run time end up in the right place in ROM (if const) or RAM (if not
>> const). The other notation just allocates space in RAM (in bss) with
>> nothing to initialise it (not even something in ROM to copy to RAM to
>> set it up). The one with " => " is the wrong'un in this picture.
>>
>
> The compiler is wrong, wrong, wrong. Since it's placed it in .bss, it's
> clearly ignored the initialisation values. The compiler is broken.
>
I've had a think about this to try and come up with a scenario in which
the compiler isn't as broken as it appears to be and I do have one
suggestion.
It occured to me that the apparently broken compiler, when it sees named
aggregates, may be choosing to setup the array at elaboration time instead
of at compilation time.
In this case, it would be correct for the array to be placed in .bss,
because the elaboration code, which is executed before the procedure
itself, would setup the array at runtime.
If true, the question then becomes if the expected elaboration code is
been suppressed at build time, or if the compiler generated elaboration
code is not been copied to the final executable correctly because
something is wrong in the linker script.
If it's a elaboration problem, this may catch you in different unrelated
areas as well, so it may be worth you considering this possibility even
if you have what appears to be a workaround for the original problem.
Simon.
--
Simon Clubley, clubley at remove_me.eisner.decus.org-Earth.UFP
Microsoft: Bringing you 1980s technology to a 21st century world
More information about the Info-vax
mailing list