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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,69d70de9327389c7 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-07-02 13:24:57 PST Newsgroups: comp.lang.ada Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!bloom-beacon.mit.edu!nycmny1-snh1.gtei.net!news.gtei.net!news-out.visi.com!hermes.visi.com!uunet!ash.uu.net!world!news From: Robert A Duff Subject: Re: Simple Question - Direct Access to memory with ADA Sender: news@world.std.com (Mr Usenet Himself) Message-ID: Date: Tue, 2 Jul 2002 20:23:59 GMT References: <3D21E96E.7030109@thedomain.net> NNTP-Posting-Host: shell01.theworld.com Organization: The World Public Access UNIX, Brookline, MA X-Newsreader: Gnus v5.7/Emacs 20.7 Xref: archiver1.google.com comp.lang.ada:26820 Date: 2002-07-02T20:23:59+00:00 List-Id: Fredrick Smith writes: > Sorry for the simple question - I was wondering the most efficient way > (moral arguments aside) to get direct access to memory in ADA 95 > (specifically using the GNAT compiler) - assuming the OS allows access > to it. Its quite > easy to do in C (a couple of lines to write to a memory location) > > *my_int_ptr = (int *) 0xF00BA; Don't you mean something like this: my_int_ptr = (int *) 0xF00BA; *my_int_ptr = 123; ? > etc.. > This can easily be macro/funcionalized. > > I could use an Address Clause for each location in memory I wish to > access, > this could become tiresome for large chunks of memory. If you have a large chunk of memory, you can use an address for an array that covers that chunk. Or you can use Address_To_Access_Conversions. Or you can use Unchecked_Conversions from integers to pointers. There is also address arithmetic in System.Storage_Elements. And Integer_To_Address (or something like that). >... There doesnt seem > to be any provided service from gnat system packages to perform this > function (probably for very good reasons). > > Anyone have an efficient method to do this? will I need to use the > pragma Atomic as well? It depends what you're doing. If some piece of hardware is messing around with location 0xF00FA at the same time as your program, you need some form of synchronization. Pragma Atomic might well be the right form. >... Am I going to have to resort to Unchecked_Conversion? I'm not sure why you call it "resort to Unchecked_Conversion". The "(int *)" in the above C code is an unchecked conversion. If you program at this level, you have to "resort" to *some* low-level (unchecked) features. Unchecked_Conversion is no less "checked" than address clauses, for example. - Bob