From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.5-pre1 Date: 13 Aug 93 17:57:48 GMT From: cgl!sgiblab!darwin.sura.net!mlb.semi.harris.com!x102a!scook@ucbvax.Berkel ey.EDU (sr cook) Subject: Re: Data Overlays Message-ID: <1993Aug13.175748.5916@mlb.semi.harris.com> List-Id: 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