comp.lang.ada
 help / color / mirror / Atom feed
From: smithd@software.org (Doug Smith)
Subject: Default initialization and address clauses.
Date: 8 Apr 91 17:40:20 GMT	[thread overview]
Message-ID: <1991Apr8.174020.8176@software.org> (raw)

-- According to the Ada LRM, 13.5.8, address clauses should not be used to achieve overlays
-- of objects or overlays of program units.  However, I have unwittingly used just that
-- approach to hide information, create freelists of allocated memory, etc.  So far the
-- compilers I have used behave as expected, with one inconsistency.

-- Should an object that has an address clause also have default initializations applied?
-- Explicit initializations are not a big problem (I can control that).  But several times
-- now, my concientious attempts at providing reasonable default initialization while
-- going to extremes to hide implementation details has created portability problems.

-- The DEC Ada compiler does the initialization.  The Verdix compiler (several versions
-- old now) does not.  My first thought was that the DEC Ada compiler was correct, but
-- I'm not so sure.  If this feature were not so convenient and powerful, who would care?
-- I invite your comments on which behavior you believe is appropriate.  Keep in mind that
-- this is a very simplified example of the technique.  (Unchecked_Conversion does not
-- work in other situations I have encountered!)


with Text_IO;
with System;

procedure Test is
begin

   Try_Access_Types:
   declare

      type Pointer is access Integer;

      Pointer_Value   : Pointer := new Integer;
      Pointer_Value_2 : Pointer;               -- Overlay !!!
      for Pointer_Value_2 use at Pointer_Value'Address;

   begin
      if Pointer_Value_2 = null then
         Text_IO.Put_Line ("Your compiler initializes pointer " &
                           "declarations even with representation clauses.");
      else
         Text_IO.Put_Line ("Your compiler fails to initialize pointer " &
                           "declarations with representation clauses.");
      end if;
   end Try_Access_Types;


   Try_Record_Types:
   declare

      type R is record
          I : Integer := 13;
      end record;

      R_Value       : R := R'( I => 17 );
      R_Value_2     : R;                 -- Overlay !!!
      for R_Value_2 use at R_Value'Address;

   begin
      if    R_Value_2.I = 13 then
         Text_IO.Put_Line ("Your compiler initializes record component " &
                           "declarations even with representation clauses.");
      elsif R_Value_2.I = 17 then
         Text_IO.Put_Line ("Your compiler fails to initialize record component " &
                           "declarations with representation clauses.");
      end if;
   end Try_Record_Types;

end;

             reply	other threads:[~1991-04-08 17:40 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1991-04-08 17:40 Doug Smith [this message]
1991-04-09 19:38 ` Default initialization and address clauses Charles H. Sampson
replies disabled

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