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,ca0d61d183eeb881 X-Google-Attributes: gid103376,public From: mgk25@cl.cam.ac.uk (Markus Kuhn) Subject: Re: Direct memory access Date: 1999/03/25 Message-ID: <7de3hl$7tv$1@pegasus.csx.cam.ac.uk>#1/1 X-Deja-AN: 459061224 References: <7dda9v$bf3$1@fleetstreet.Austria.EU.net> <7ddj0q$gh6$1@nnrp1.dejanews.com> Organization: U of Cambridge Computer Lab, UK Newsgroups: comp.lang.ada Date: 1999-03-25T00:00:00+00:00 List-Id: "Joachim Schroeer" wrote: >I'm using GNAT v3.11 for IBM PC platforms. > >I'm trying to write some code to allow direct access to memory (for >testing memory on an embedded system). I simply want something like 'C' >pointers, so I can write/read values to a given memory address. Pointer arithmetic in Ada95 is defined in the package System.Storage_Elements. You can transform an integer into an address using function To_Address(Value : Integer_Address) return Address; You can do pointer arithmetic on type Address. You can convert an address into a pointer for some object type using the generic package System.Address_To_Access_Conversions which contains the function function To_Pointer(Value : Address) return Object_Pointer; This is all you need to do all the messy thing that you can do with C pointer arithmetic. It is just quite a bit more bureaucratic in Ada, because you have to add one more line than in the corresponding C code to instantiate Address->pointer conversion function, and because Ada (unlike C, BCPL, and Assembler) does distinguish between integers and addresses and therefore requires an additional type conversion. Note that all these conversion functions are intrinsic functions, therefore the compiler should not generate a single instruction for them and the resulting code should be identical to what you get in C with just *(sometype *)x = y; . Ada clearly works hard to discourage direct memory access and pointer arithmetic, therefore developpers are more likely to encapsulate these clumsy accesses in separate packages, and as a result the dangerous unchecked code is concentrated in one place and not spread throught the software. http://www.adahome.com/rm95/rm9x-13-07.html Markus -- Markus G. Kuhn, Computer Laboratory, University of Cambridge, UK Email: mkuhn at acm.org, WWW: