comp.lang.ada
 help / color / mirror / Atom feed
From: cgl!sgiblab!darwin.sura.net!mlb.semi.harris.com!x102a!scook@ucbvax.Berkel ey.EDU  (sr cook)
Subject: Re: Data Overlays
Date: 13 Aug 93 17:57:48 GMT	[thread overview]
Message-ID: <1993Aug13.175748.5916@mlb.semi.harris.com> (raw)

In article <1993Aug13.124835.18422@iplmail.orl.mmc.com> rgilbert@orl.mmc.com wr
ites:
>    *** Stuff Deleted *** 
>
>Many times I have wanted to create two different types to look at the
>same object.  An example might be a record structure which is to be
>output via some DMA device which expects the data to look like an 
>array of bytes.  Anyway I've come up with two different methods to
>implement this.
>
>Method 1 :  Use an access type of one of the types and assign the address
>            (using unchecked conversion) of the object declare of the
>            other type.
>
>   I have used this method on several occasions and it works just fine.  Howev
er,
>   it does seem a little complicated and makes the assumption that an object
>   of an access type is implemented using the address of the object.
>
>Method 2:  Just use a representation clause to map one of the objects to the
>           address of the other.
>
>      X : SAMPLE_REC_TYPE;
>      Y : BYTE_ARRAY_TYPE;
>      for Y use at X'address;
>
>   This seems to be much more straight forward and makes no assumptions about
>   the implementation.  But when this method is used a compiler (Telesoft)
>   warning is issued to the affect that the representation clause should not
>   be used to produce overlayed data?
>
>Question:  Which of the above methods is prefered?  Is there a better way?
>
>                           Bob

My first question is why not use Unchecked Conversion?  Do you have some size
or time constraints?  I have used something similar to your method 2, so I'll
address just that one....Note that in the RM 13.5 states "Address clauses
should not be used to achieve overlays of objects...Any program using address
clauses to achieve such effects is erroneous." 

In my embedded work I have had need to perform some low-level operations on the
hardware ( accessing devices, RAM tests, ect.) and have used run-time 
elaboration of memory-mapped objects successfully.  Consider the following:

	procedure Write_HW_Register(
	  Destination_Address : in system.address;
	  Value               : in integer ) is
	
	Register : integer;
	for Register use at Destination_Address;

	begin
	  Register := Value;
	end Write_HW_Register;

You can take this concept further and write simple routines that some
people might implement in assembly (How about a Move Data routine with
two addresses and a size...).  Be aware you can get yourself into some trouble
with this one. :)

I'll let other people argue against using this, but I would rather code these
things in Ada and be able to reuse them on different architectures than
rewrite them each time in assembley.

Stephen R. Cook
Harris Government Aerospace    

             reply	other threads:[~1993-08-13 17:57 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1993-08-13 17:57 cgl!sgiblab!darwin.sura.net!mlb.semi.harris.com!x102a!scook [this message]
  -- strict thread matches above, loose matches on Subject: below --
1993-09-01 14:36 Data Overlays David Emery
1993-09-01  4:23 Jim Lonjers
1993-08-31 20:36 dog.ee.lbl.gov!agate!howland.reston.ans.net!math.ohio-state.edu!magnus.ac
1993-08-31  3:51 Jim Lonjers
1993-08-23 14:17 Bob Crispen
1993-08-23 14:11 Alex Blakemore
1993-08-19 13:16 cs.utexas.edu!mars.tsd.arlut.utexas.edu!gardner
1993-08-19  2:18 portal!cup.portal.com!R_Tim_Coslet
1993-08-18 16:40 cis.ohio-state.edu!magnus.acs.ohio-state.edu!csn!news.den.mmc.com!iplmail
1993-08-18 16:27 Charles H. Sampson
1993-08-18 16:04 Charles H. Sampson
1993-08-18 12:55 cis.ohio-state.edu!magnus.acs.ohio-state.edu!csn!news.den.mmc.com!iplmail
1993-08-18 12:50 cis.ohio-state.edu!math.ohio-state.edu!howland.reston.ans.net!europa.eng.gtefsd.com!fs7.ece.cmu.edu!news.sei.cmu.edu!firth
1993-08-18  2:11 cis.ohio-state.edu!magnus.acs.ohio-state.edu!usenet.ins.cwru.edu!agate!do
1993-08-18  1:53 cis.ohio-state.edu!magnus.acs.ohio-state.edu!math.ohio-state.edu!howland.
1993-08-18  0:39 cis.ohio-state.edu!magnus.acs.ohio-state.edu!math.ohio-state.edu!cs.utexa
1993-08-17 15:16 Charles H. Sampson
1993-08-13 12:48 Bob Gilbert
replies disabled

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