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-Thread: 103376,d36fc3985d071e34 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!news2.google.com!news.maxwell.syr.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!newsfeed00.sul.t-online.de!newsmm00.sul.t-online.de!t-online.de!news.t-online.com!not-for-mail From: Martin Krischik Newsgroups: comp.lang.ada Subject: Re: Pointer address Date: Thu, 30 Dec 2004 13:18:32 +0100 Organization: None Message-ID: <14351388.x9hNLFkO6K@linux1.krischik.com> References: Reply-To: martin@krischik.com Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Transfer-Encoding: 8Bit X-Trace: news.t-online.com 1104413176 00 23922 nDIsr8rL20QUNts 041230 13:26:16 X-Complaints-To: usenet-abuse@t-online.de X-ID: VTlAqUZYYemOsrDSSYcQ0FmMYi3VvlcTJLqfR6Uerx+2bhRFvpNKUu User-Agent: KNode/0.8.0 Xref: g2news1.google.com comp.lang.ada:7321 Date: 2004-12-30T13:18:32+01:00 List-Id: Bj?rn wrote: > I'm trying to convert some C code into Ada. > I'm stuck on the follwing: > cpdata.dwData = 0x0001B001 (dwData being a ptr to an ulong) > > Trying to execute the code below gives me a: > EXCEPTION_ACCESS_VIOLATION > > If I change the address to 16#0001B000# the program just silently > exits/terminates without printing my put_line. > > If I try to set DwData with an unchecked_conversion instead, using > address 16#0001B001#, the Address_Image returns 16#0001B000#. > > I'm quite sure I'm doing something wrong here and need to read up a > bit on it. Could someone please give me some pointers here and maybe > the applicable parts of the ARM. > > When I compile this on win-gnat-3.15 I get the following warnings: > temp.adb:17:08: warning: default initialization of "DwData" may modify > overlaid storage > temp.adb:17:08: warning: use pragma Import for "DwData" to suppress > initialization (RM B.1(24)) > Adding an import pragma didn't seem to help more than removing the > warnings. > > Thanks > Bj�rn > > > with Interfaces.C; > with Unchecked_Conversion; > with System.Storage_Elements; > with System.Address_Image; > with Text_IO; > > procedure Temp is > > type PULONG is access all Interfaces.C.Unsigned_Long; > function PULONG_To_Address is new Unchecked_Conversion > (PULONG, System.Address); > Some_Address : constant System.Address := > System.Storage_Elements.To_Address(16#0001B000#); > DwData : PULONG; > for DwData'Address use Some_Address; > -- pragma Import (C, DwData); > begin > Text_IO.Put_Line ("dwData address = " & System.Address_Image > (PULONG_To_Address (DwData))); > end; You should not use Unchecked_Conversion. Read: http://en.wikibooks.org/wiki/Programming:Ada:Subtypes#Address_Convertion With Regards Martin -- mailto://krischik@users.sourceforge.net http://www.ada.krischik.com