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=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,5ad62cc979f6c111 X-Google-Attributes: gid103376,public From: Niklas Holsti Subject: Re: Classwide-type assignments Date: 1998/10/13 Message-ID: <362392F7.8A226D64@icon.fi>#1/1 X-Deja-AN: 400702940 Content-Transfer-Encoding: 7bit References: <6vtl8g$v42$1@nnrp1.dejanews.com> Content-Type: text/plain; charset=us-ascii Organization: Space Systems Finland Ltd Mime-Version: 1.0 Newsgroups: comp.lang.ada Date: 1998-10-13T00:00:00+00:00 List-Id: jsanchor@cs5.dasd.honeywell.com wrote: [ snip ] > I have been trying to assign classwide types with no luck. > type PARENT_TYPE is abstract tagged > record > checksum : NATURAL32; > end record; > > type PTR_TO_DATA is access all PARENT_TYPE'class; > > package CONVERT_TO_NVM_TYPE is new > SYSTEM.Address_to_Access_Conversions(PARENT_TYPE'class); > -------------------------------------------------------------- > type RAM_TYPE is new PARENT_TYPE with > record > number_1 : integer; > end record; > > RAM_object : aliased RAM_TYPE; > RAM_ptr : CONVERT_TO_NVM_TYPE.Object_Pointer; > > RAM_ptr := CONVERT_TO_NVM_TYPE.To_Pointer(RAM_object.all'address); > ptr_to_RAM := PTR_TO_DATA(ptr_to_data); --casting *********** (should perhaps be RAM_ptr?) > ----------------------------------------------------------- > > NVM_Address : constant SYSTEM.Address := > SYSTEM.STORAGE_ELEMENTS.To_Address(16#00E00000#); > > NVM_ptr : CONVERT_TO_NVM_TYPE.Object_Pointer; > > --get an access type to the location in NVM where data is stored. > NVM_ptr := CONVERT_TO_NVM_TYPE.To_Pointer(NVM_Address); > ptr_to_NVM := PTR_TO_DATA(NVM_PTR); > > AND then, > > ptr_to_NVM.all := ptr_to_RAM.all; <-- the following statement compiles. > > But nothing happens, when I run the code. The target of the assignment (ptr_to_NVM.all) is of class-wide type and the expression (ptr_to_RAM.all) is dynamically tagged. This means that the assignment includes a check that the tag of the target is the same as the tag of the expression, by LRM 5.2(10). Your program (at least the part shown) does not initialize the target area (at NVM_Address), so the tag check will access an undefined tag value. I'm confident that this means that the program is erroneous (ie. the effects are unpredictable). I think but am not sure that this follows from LRM 13.3(13). I don't think that you can use ":=" to move class-wide data to an uninitialized memory area. Perhaps you could make a custom Storage Pool that allocates target objects from the NV RAM? Then you could clone the RAM object into the NV RAM using "new" for the NV RAM Storage Pool. A simpler approach would be to use a low-level memory copy based on RAM_object'size. You could implement a generic copy package parametrized by the type, to hide the low-level stuff. Sorry for not being very specific in my suggestions, but I hope they give you some pointers. > Jay S. Niklas Holsti