comp.lang.ada
 help / color / mirror / Atom feed
From: tmoran@acm.org
Subject: Re: Pointer address
Date: Thu, 30 Dec 2004 12:51:05 -0600
Date: 2004-12-30T12:51:05-06:00	[thread overview]
Message-ID: <wp6dnZVo_NWE00ncRVn-3A@comcast.com> (raw)
In-Reply-To: 1224531.Y4V0fVubSt@jellix.jlfencey.com

>>cpdata.dwData = 0x0001B001 (dwData being a ptr to an ulong)
  This says dwData is a pointer whose value is 0x0001B001.
>>  DwData : PULONG;
>>  for DwData'Address use Some_Address;
  This says DwData itself is at Some_Address.  The value of DwData is null,
unless you manage to override the default with a pragma Import, in which
case the pointer DwData will point to the address given by whatever
happened to be in the bytes at Some_Address.

>if dwData really is a pointer to some data at a fixed address you could
>declare the data itself and apply the address clause to it directly.
>Again, this is Ada -> no need for pointers.  ;-)
>...
>   DwData : Interfaces.C.Unsigned_Long;
>   for DwData'Address use Some_Address;
  Yes, and (with *cpdata.dwData changing to DwData) probably the correct
translation of the (non-Windows) design.  But since cpdata.dwData is a
variable, there could be other code like
  cpdata.dwData = 0x0001B011;
  cpdata.dwData = 0x0002C022;
etc, in which case he really would need to use pointers.

>Hmm, one problem: if I change the address to 16#0001B001#, I get
>
>"raised PROGRAM_ERROR : temp.adb:13 misaligned address value".
  Objects of type "access all Interfaces.C.Unsigned_Long", most likely
have an alignment of 4, and ARM 13.3(27) says "Program execution is
erroneous if an Address clause is given that conflicts with the
Alignment."  16#1B001# is not a multiple of 4.

>What was the target architecture/OS of the original C-Code? Using fixed
>addresses looks like it was assuming DOS or some other system with
>fixed memory areas (like some microcontroller stuff). Such code simply
>will not work with Windows.
  That's a bit strong.  The address will be interpreted as a location
in the program's virtual address space, which might be, though probably
isn't, what was meant.  Perhaps 16#1B001# was an absolute address
in a microcontroller, or an offset into the data segment in a large-model
DOS program, or an IO mapped address in some other architecture.  Porting
this C program to another architecture certainly requires more than a
transliteration into Ada.



  reply	other threads:[~2004-12-30 18:51 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
2004-12-30 12:23 ` Vinzent 'Gadget' Hoefler
2004-12-30 18:51   ` tmoran [this message]
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