comp.lang.ada
 help / color / mirror / Atom feed
From: Niklas Holsti <nholsti@icon.fi>
Subject: Re: Classwide-type assignments
Date: 1998/10/13
Date: 1998-10-13T00:00:00+00:00	[thread overview]
Message-ID: <362392F7.8A226D64@icon.fi> (raw)
In-Reply-To: 6vtl8g$v42$1@nnrp1.dejanews.com

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




  reply	other threads:[~1998-10-13  0:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-10-12  0:00 Classwide-type assignments jsanchor
1998-10-13  0:00 ` Niklas Holsti [this message]
1998-10-15  0:00   ` Classwide-type assignments [longish] Niklas Holsti
replies disabled

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