comp.lang.ada
 help / color / mirror / Atom feed
From: prichtmyer@yahoo.com (Peter Richtmyer)
Subject: Re: Compiler default initialization of array types
Date: 17 Oct 2002 15:39:44 -0700
Date: 2002-10-17T22:39:44+00:00	[thread overview]
Message-ID: <1b585154.0210171439.47ab4605@posting.google.com> (raw)
In-Reply-To: slrnaqtdlb.q0.lutz@taranis.iks-jena.de

Lutz Donnerhacke <lutz@iks-jena.de> wrote in message news:<slrnaqtdlb.q0.lutz@taranis.iks-jena.de>...
> * Sebastian wrote:
> > I wonder if Ada always assignes Array types with default values?
> 
> It can happen.
> 
> > In case this is true; is there some way to suppress this feature?
> 
> pragma Import(Ada, array_variable); -- directly after the definition.

I have used the "Pragma Import" successfully in some circumstances,
but for a simple array, Gnat would not allow it. The error message
looks strange to me, maybe a "bug". See below.

(Gnat does not assign default values, the example shows what happens
 if values are assigned in the array using the record...)


with text_io;
procedure artest is

    type r is 
        record 
            i: integer := 1;
        end record;             
    pragma pack (r);
    for r'size use 32;    

    type a_t is array (1 .. 2) of r;
    for a_t'size use 64;

    type i_t is array (1 .. 2) of integer;
    for i_t'size use 64;

    b : a_t;    
    -- pragma import (Ada, b);   -- Gnat 3.14p NOT LEGAL:   
artest.adb:17: undefined reference to `b'
    
    c : i_t := (others => 3);
    d : a_t;
    for d'address use c'address;


    e : i_t := (others => 5);
    f : a_t;
    for f'address use e'address;
    pragma import (Ada, f);
    
begin 
   for j in a_t'range loop     
      text_io.put_line ("-- b(" & integer'image(j) & ").i is " &
integer'image(b(j).i));
      text_io.put_line ("-- d(" & integer'image(j) & ").i is " &
integer'image(d(j).i));
      text_io.put_line ("-- f(" & integer'image(j) & ").i is " &
integer'image(f(j).i));
      text_io.put_line ("-- --------------------");   
   end loop;   
   
-- b( 1).i is  1
-- d( 1).i is  1
-- f( 1).i is  5    (THE PRAGMA SUPPRESSED INITIALIZATION)
-- --------------------
-- b( 2).i is  1
-- d( 2).i is  1
-- f( 2).i is  5 
-- -------------------- 
end artest;

Peter



  reply	other threads:[~2002-10-17 22:39 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-10-17 12:55 Compiler default initialization of array types Sebastian
2002-10-17 13:10 ` Lutz Donnerhacke
2002-10-17 22:39   ` Peter Richtmyer [this message]
2002-10-17 13:42 ` Matthew Heaney
2002-10-17 23:57   ` Robert A Duff
2002-10-18  9:50     ` Larry Kilgallen
2002-10-18 14:40       ` Robert A Duff
2002-10-18 15:04         ` Larry Kilgallen
2002-10-18 13:36     ` Matthew Heaney
2002-10-18 15:28     ` Wes Groleau
  -- strict thread matches above, loose matches on Subject: below --
2002-10-17 14:23 Grein, Christoph
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox