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.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,de41c0d7c45160c8 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 1995-03-13 12:42:33 PST Path: bga.com!news.sprintlink.net!cs.utexas.edu!usc!news.cerf.net!hacgate2.hac.com!atc-69!dkusu From: dkusu@atc-1s.hac.com (David Kusuda) Newsgroups: comp.lang.ada Subject: Re: Pointers Date: 13 Mar 1995 20:16:44 GMT Organization: Guardian ATC - Hughes Aircraft Company Distribution: world Message-ID: <3k297c$rg4@hacgate2.hac.com> References: <794482546snz@jonf.demon.co.uk> Reply-To: dkusu@atc-1s.hac.com NNTP-Posting-Host: atc-69.hac.com Date: 1995-03-13T20:16:44+00:00 List-Id: In article 794482546snz@jonf.demon.co.uk, Jon@jonf.demon.co.uk (Jon Freeman) writes: >Can anyone tell me if it is possible to read the contents of a specified >memory location in ada or to read the contents of, say, an integer variable >stored in a known location? >Any help greatly appreciated. > >-- >Jon Freeman >jon@jonf.demon.co.uk There are (at least) two ways to accomplish what you want. One may be technically illegal depending on what you are trying to do, however. The first method is to create an access type to the object in memory that you are trying to examine. You can then use an Unchecked_Conversion to convert the desired address to your access type, for example: type Int_Ptr_Type is access Integer; function Addr_To_Ptr is new Unchecked_Conversion ( Source => System.Address, Target => Int_Ptr_Type); Int_Ptr : Int_Ptr_Type := Addr_To_Ptr (Int_Ptr'Address); You can also use an Unchecked_Conversion to point at a specific address too: function Int_To_Ptr is new Unchecked_Conversion ( Source => Integer, Target => Int_Ptr_Type); Int_Ptr : Int_Ptr_Type := Int_To_Ptr (16#10000#); You can then read or write to the specified memory location using regular access dereferencing: Int_Val : Integer := Int_Ptr.all; . . . Int_Ptr.all := 5; Now, for the potentially "illegal" method. This method uses the address representation clause. Here, you would declare an object and then use an address clause to locate the object in memory. Int_Val : Integer; for Int_Val use at at 16#10000#; Accessing Int_Val has the effect of directly accessing the specified memory location. If you were programming a memory mapped device, this would be a typical method of doing that. The illegality of the above is mentioned in the LRM (section 13.5): "Address clauses should not be used to achieve overlays of objects or overlays of program units. Nor should a given interrupt be linked to more than one entry. Any program using address clauses to achieve such effects is erroneous." I hope this helps. Dave