comp.lang.ada
 help / color / mirror / Atom feed
* Pointer address
@ 2004-12-30 11:29 Bj?rn
  2004-12-30 12:18 ` Martin Krischik
  2004-12-30 12:23 ` Vinzent 'Gadget' Hoefler
  0 siblings, 2 replies; 6+ messages in thread
From: Bj?rn @ 2004-12-30 11:29 UTC (permalink / raw)


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;



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2004-12-31  9:57 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-12-30 11:29 Pointer address Bj?rn
2004-12-30 12:18 ` Martin Krischik
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox