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.1 required=5.0 tests=AXB_XMAILER_MIMEOLE_OL_024C2, BAYES_00,MAILING_LIST_MULTI,REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,d2cba5965c7bfcd5 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-03-03 14:25:04 PST Path: archiver1.google.com!news1.google.com!sn-xit-02!supernews.com!news.tele.dk!small.news.tele.dk!213.56.195.71!fr.usenet-edu.net!usenet-edu.net!enst!enst.fr!not-for-mail From: "David C. Hoos, Sr." Newsgroups: comp.lang.ada Subject: Re: 64bit access to an array of 8bit values Date: Sun, 3 Mar 2002 16:24:24 -0600 Organization: ENST, France Sender: comp.lang.ada-admin@ada.eu.org Message-ID: References: <3C823A1A.6030006@users.sf.net> Reply-To: comp.lang.ada@ada.eu.org NNTP-Posting-Host: marvin.enst.fr Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Trace: avanie.enst.fr 1015194303 63204 137.194.161.2 (3 Mar 2002 22:25:03 GMT) X-Complaints-To: usenet@enst.fr NNTP-Posting-Date: Sun, 3 Mar 2002 22:25:03 +0000 (UTC) Return-Path: X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2600.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 Errors-To: comp.lang.ada-admin@ada.eu.org X-BeenThere: comp.lang.ada@ada.eu.org X-Mailman-Version: 2.0.8 Precedence: bulk List-Help: List-Post: List-Subscribe: , List-Id: comp.lang.ada mail<->news gateway List-Unsubscribe: , Errors-To: comp.lang.ada-admin@ada.eu.org X-BeenThere: comp.lang.ada@ada.eu.org Xref: archiver1.google.com comp.lang.ada:20737 Date: 2002-03-03T16:24:24-06:00 How about something like this? with Ada.Text_IO; with Interfaces; procedure Test is type Ram_Range is range 0 .. 2 ** 12 -1; Ram : array (Ram_Range) of Interfaces.Unsigned_8; function Value (Index : Ram_Range) return Interfaces.Unsigned_8 is Result : Interfaces.Unsigned_8; for Result'Address use Ram (Index)'Address; begin return Result; end Value; function Value (Index : Ram_Range) return Interfaces.Unsigned_64 is Result : Interfaces.Unsigned_64; for Result'Address use Ram (Index)'Address; begin return Result; end Value; procedure Set (Value : Interfaces.Unsigned_8; Index : Ram_Range) is Target : Interfaces.Unsigned_8; for Target'Address use Ram (Index)'Address; begin Target := Value; end Set; procedure Set (Value : Interfaces.Unsigned_64; Index : Ram_Range) is Target : Interfaces.Unsigned_64; for Target'Address use Ram (Index)'Address; begin Target := Value; end Set; Value_64 : Interfaces.Unsigned_64; begin Set (Interfaces.Unsigned_64'(12345678901234567890), 1234); Value_64 := Value (1234); Ada.Text_IO.Put_Line ("Interfaces.Unsigned_64 value:" & Interfaces.Unsigned_64'Image (Value_64)); for B in Ram_Range'(1234) .. 1241 loop Ada.Text_IO.Put_Line ("Interfaces.Unsigned_8 value at index" & Ram_Range'Image (B) & ":" & Interfaces.Unsigned_8'Image (Value (B))); end loop; end Test; ----- Original Message ----- From: "Dave Poirier" Newsgroups: comp.lang.ada To: Sent: March 03, 2002 8:58 AM Subject: 64bit access to an array of 8bit values > I'm trying to modelize a small virtual machine, and I'm stuck on the > memory model. I'm defining the memory as an array of 8bit values, so > that I am able to access every byte individually. The problem comes > when I try to access them with other data size, like 16/32/64bit. GNAT > simply refuses to do the pointer conversion (yeah, probably a bad habit). > > So, what would be a "clean" way to do it? here's what I tried > > ------ > procedure test is > type Bit8 is mod 2**8; > type Bit64 is mod 2**64; > type Bit8Acc is access Bit8; > type Bit64Acc is access Bit64; > > type RamRange is range 0 .. 4000; > > Ram : array (RamRange) of aliased Bit8; > Value : Bit64Acc; > > begin > Value := Ram(0)'Access; > end test; > ------ > > test.adb:14:18: expected type "Bit64Acc" defined at line 6 > test.adb:14:18: found type access to "bit8" defined at line 14 > > and also.. > ------ > procedure test is > type Bit8 is mod 2**8; > type Bit64 is mod 2**64; > type Bit8Acc is access all Bit8; > type Bit64Acc is access all Bit64; > > type RamRange is range 0 .. 4000; > > Ram : array (RamRange) of aliased Bit8; > Value : Bit64Acc; > > begin > Value := Bit64Acc(Ram(0)'Access); > end test; > ------ > > test.adb:14:12: argument of conversion cannot be access > test.adb:14:12: use qualified expression instead > > I'm just a smooth skinned Ada95 newbie, so don't get too big weapons to > send replies ;) > > Thanks for helping me learn :) > EKS - Dave Poirier > > _______________________________________________ > comp.lang.ada mailing list > comp.lang.ada@ada.eu.org > http://ada.eu.org/mailman/listinfo/comp.lang.ada >