comp.lang.ada
 help / color / mirror / Atom feed
* Default initialization and address clauses.
@ 1991-04-08 17:40 Doug Smith
  1991-04-09 19:38 ` Charles H. Sampson
  0 siblings, 1 reply; 2+ messages in thread
From: Doug Smith @ 1991-04-08 17:40 UTC (permalink / 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;

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~1991-04-09 19:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1991-04-08 17:40 Default initialization and address clauses Doug Smith
1991-04-09 19:38 ` Charles H. Sampson

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