Pointer address

From: Bj?rn (ssh9614_at_hotmail.com)
Date: 12/30/04


Date: 30 Dec 2004 03:29:10 -0800

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;