[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
Thu Aug 23 20:52:58 EDT 2012
On 2012-08-23, John Wallace <johnwallace4 at gmail.com> wrote:
>
> Who speaks Ada round here? The following example illustrates the
> principle rather than the exact syntax (which, being Ada, is
> inevitably much more complex than I can remember, though I can happily
> read Ada and have been doing so for far too long).
>
> 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 wish you could tell us which compiler this is, but I know you said
earlier that you are not free to discuss compilers here.
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