From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=BAYES_00,INVALID_DATE autolearn=no autolearn_force=no version=3.4.4 Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!elroy.jpl.nasa.gov!decwrl!mcnc!uvaarpa!software.org!smithd From: smithd@software.org (Doug Smith) Newsgroups: comp.lang.ada Subject: Default initialization and address clauses. Summary: Behavior is inconsistent across compilers. Keywords: Ada, compiler, erroneous, address, initialization Message-ID: <1991Apr8.174020.8176@software.org> Date: 8 Apr 91 17:40:20 GMT Sender: usenet@software.org (Usenet News/Mail Support) Organization: spd List-Id: -- 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;