comp.lang.ada
 help / color / mirror / Atom feed
* Access to Address conversion question
@ 1996-03-21  0:00 Jerry van Dijk
  1996-03-22  0:00 ` Norman H. Cohen
  1996-03-22  0:00 ` Laurent Guerby
  0 siblings, 2 replies; 4+ messages in thread
From: Jerry van Dijk @ 1996-03-21  0:00 UTC (permalink / raw)


It might be just me again, but I cannot figure out how to convert an access 
type to an address, as in assigning Address_C in the code below. GNAT (3.03)
tells me I have an invalid parameter list in the call to To_Address here ?

Of course I realize that although my C background makes me view Some_Object_Ptr
as just an alias for Some_Object'ACCESS it is, in fact, a different type.

However, LRM 13.7.2 (3) led me to believe it should be possible... 

with System.Address_To_Access_Conversions;
with System.Storage_Elements; use System.Storage_Elements;

procedure Demo is

   type Some_Object is array (1..10) of Character;
   type Some_Object_Ptr is access all Some_Object;

   package Some_Object_Conversion is
      new System.Address_To_Access_Conversions(Some_Object);
   use Some_Object_Conversion;

   A_Object     : aliased Some_Object;
   A_Object_Ptr : Some_Object_Ptr := A_Object'ACCESS;

   Address_A, Address_B, Address_C : Integer;

begin
   Address_A := Integer(To_Integer(A_Object'ADDRESS));
   Address_B := Integer(To_Integer(To_Address(A_Object'ACCESS)));
   Address_C := Integer(To_Integer(To_Address(A_Object_Ptr)));
end Demo;

--
-----------------------------------------------------------------------
--  Jerry van Dijk       --   e-mail: jerry@jvdsys.nextjk.stuyts.nl  --
--  Banking Consultant   --              Member Team-Ada             -- 
--  Ordina Finance BV    --    Located at Haarlem, The Netherlands   --
-----------------------------------------------------------------------
-- I do not speak for my employer, my employer does not speak for me --
-----------------------------------------------------------------------




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

* Re: Access to Address conversion question
  1996-03-21  0:00 Access to Address conversion question Jerry van Dijk
  1996-03-22  0:00 ` Norman H. Cohen
@ 1996-03-22  0:00 ` Laurent Guerby
  1 sibling, 0 replies; 4+ messages in thread
From: Laurent Guerby @ 1996-03-22  0:00 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=US-ASCII 19: 52:09 GMT, Size: 1344 bytes --]

Jerry van Dijk writes
: It might be just me again, but I cannot figure out how to convert an access 
: type to an address, as in assigning Address_C in the code below. GNAT (3.03)
: tells me I have an invalid parameter list in the call to To_Address here ?
[source and comments deleted]

You  should have a  close  look   to  the spec of   System.Address_To_
Access_Conversions : (taken from the GNAT sources) 

generic
   type Object (<>) is limited private;
 
package System.Address_To_Access_Conversions is
pragma Preelaborate (Address_To_Access_Conversions);
 
   type Object_Pointer is access all Object;
 
   function To_Pointer (Value : Address)        return Object_Pointer;
   function To_Address (Value : Object_Pointer) return Address;
 
   pragma Convention (Intrinsic, To_Pointer);
   pragma Convention (Intrinsic, To_Address);
 
end System.Address_To_Access_Conversions;

   Once you instanciate it with ab "Object" type,  it provides you the
"access all"  type,  and you should  use this   one to avoid  compiler
complaints about silly type mismatch ;-).

-- 
--  Laurent Guerby, student at Telecom Bretagne (France), Team Ada
--  "Use the Source, Luke. The Source will be with you, always (GPL)"
--  http://www-eleves.enst-bretagne.fr/~guerby/ (GATO Project)
--  Try GNAT, the GNU Ada 95 compiler (ftp://cs.nyu.edu/pub/gnat)




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

* Re: Access to Address conversion question
  1996-03-21  0:00 Access to Address conversion question Jerry van Dijk
@ 1996-03-22  0:00 ` Norman H. Cohen
  1996-03-23  0:00   ` Jerry van Dijk
  1996-03-22  0:00 ` Laurent Guerby
  1 sibling, 1 reply; 4+ messages in thread
From: Norman H. Cohen @ 1996-03-22  0:00 UTC (permalink / raw)


In article <DoMv6y.2p@jvdsys.nextjk.stuyts.nl>, jerry@jvdsys.nextjk.stuyts.nl
(Jerry van Dijk) writes: 

|> It might be just me again, but I cannot figure out how to convert an access
|> type to an address, as in assigning Address_C in the code below. GNAT (3.03)
|> tells me I have an invalid parameter list in the call to To_Address here ?
...
|>
|> with System.Address_To_Access_Conversions;
|> with System.Storage_Elements; use System.Storage_Elements;
|>
|> procedure Demo is
|>
|>    type Some_Object is array (1..10) of Character;
|>    type Some_Object_Ptr is access all Some_Object;
|>
|>    package Some_Object_Conversion is
|>       new System.Address_To_Access_Conversions(Some_Object);
|>    use Some_Object_Conversion;
|>
|>    A_Object     : aliased Some_Object;
|>    A_Object_Ptr : Some_Object_Ptr := A_Object'ACCESS;
|>
|>    Address_A, Address_B, Address_C : Integer;
|>
|> begin
|>    Address_A := Integer(To_Integer(A_Object'ADDRESS));
|>    Address_B := Integer(To_Integer(To_Address(A_Object'ACCESS)));
|>    Address_C := Integer(To_Integer(To_Address(A_Object_Ptr)));
|> end Demo;

If AAC is an instance of System.Address_To_Access_Conversions, then
AAC.To_Address takes a parameter of type AAC.Object_Pointer.  Your actual
parameter, A_Object_Ptr, belongs to a distinct access type,
Some_Object_Ptr, that you have declared yourself.  (Two type declarations
always create two distinct types, even if the declarations contain
identical definitions.)  The fix is to change the declaration of
A_Object_Ptr to: 

    A_Object_Ptr : Object_Ptr := A_Object'ACCESS;

or, equivalently, to: 

    A_Object_Ptr : Some_Object_Conversion.Object_Ptr := A_Object'ACCESS;

--
Norman H. Cohen    ncohen@watson.ibm.com




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

* Re: Access to Address conversion question
  1996-03-22  0:00 ` Norman H. Cohen
@ 1996-03-23  0:00   ` Jerry van Dijk
  0 siblings, 0 replies; 4+ messages in thread
From: Jerry van Dijk @ 1996-03-23  0:00 UTC (permalink / raw)


Thanks for the responses! 

Norman H. Cohen (ncohen@watson.ibm.com) wrote:

:     A_Object_Ptr : Object_Ptr := A_Object'ACCESS;

<PING!>

Yes, of course!

--
-----------------------------------------------------------------------
--  Jerry van Dijk       --   e-mail: jerry@jvdsys.nextjk.stuyts.nl  --
--  Banking Consultant   --              Member Team-Ada             -- 
--  Ordina Finance BV    --    Located at Haarlem, The Netherlands   --
-----------------------------------------------------------------------
-- I do not speak for my employer, my employer does not speak for me --
-----------------------------------------------------------------------




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

end of thread, other threads:[~1996-03-23  0:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-03-21  0:00 Access to Address conversion question Jerry van Dijk
1996-03-22  0:00 ` Norman H. Cohen
1996-03-23  0:00   ` Jerry van Dijk
1996-03-22  0:00 ` Laurent Guerby

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