From: Martin Krischik <martin@krischik.com>
Subject: Re: Pointer address
Date: Thu, 30 Dec 2004 13:18:32 +0100
Date: 2004-12-30T13:18:32+01:00 [thread overview]
Message-ID: <14351388.x9hNLFkO6K@linux1.krischik.com> (raw)
In-Reply-To: d56673df.0412300329.685a0f65@posting.google.com
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
next prev parent reply other threads:[~2004-12-30 12:18 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-12-30 11:29 Pointer address Bj?rn
2004-12-30 12:18 ` Martin Krischik [this message]
2004-12-30 12:23 ` Vinzent 'Gadget' Hoefler
2004-12-30 18:51 ` tmoran
2004-12-31 9:57 ` Vinzent 'Gadget' Hoefler
2004-12-31 9:49 ` Björn
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox