comp.lang.ada
 help / color / mirror / Atom feed
From: kst@thomsoft.com (Keith Thompson)
Subject: Re: How to print Task_ID type? (GNAT SunOS)
Date: 1996/04/05
Date: 1996-04-05T00:00:00+00:00	[thread overview]
Message-ID: <DpE0yF.L65@thomsoft.com> (raw)
In-Reply-To: 31642F61.1D2B@ee.ubc.ca

In <31642F61.1D2B@ee.ubc.ca> Greg Bond <bond@ee.ubc.ca> writes:
[...]
> Indeed it is. My oversight. This function does not handle the more 
> general problem I posed though. Is there a general facility for printing 
> access types?

Not directly.  Unchecked_Conversion to an integer type (signed or
unsigned) of the same size, followed by 'Image on the integer type,
is likely to give you what you're probably looking for on most or all
implementations.  Be aware, though, that there's no guarantee that
there is an integer type of the same size as a given access type, or
that all access types are the same size (for example, GNAT uses 64-bit
"fat pointers" for access to unconstrained arrays).

Another possibility is something like this:

   declare
      P: Some_Access_Type := Some_Value;
      package SSE renames System.Storage_Elements;
   begin
      if P = null then
	 Put_Line("P = null");
      else
	 Put_Line("P = " & SSE.Integer_Address'Image
			      (SSE.To_Integer(P.all'Address)));
      end if;
   end;

Note, however, that the value stored in an access object isn't necessarily
the address of the designated object.  It could include or point to a
descriptor, among many other possibilities.

The generic package System.Address_To_Access_Conversions includes a
function to convert from an access type to System.Address, which can then
be converted to an integer type by System.Storage_Elements.To_Integer.
However, System.Address_To_Access_Conversions only uses the access
type Object_Pointer, which it declares itself; it won't operate on an
arbitrary access type.

A more relevant question might be, why do you want to print access types?
If you just want to display them for debugging purposes, a non-portable
solution involving Unchecked_Conversion is probably good enough.
If you have something else in mind, perhaps you're trying to solve the
wrong problem.

-- 
Keith Thompson (The_Other_Keith) kst@thomsoft.com
TeleSoft^H^H^H^H^H^H^H^H Alsys^H^H^H^H^H Thomson Software Products
10251 Vista Sorrento Parkway, Suite 300, San Diego, CA, USA, 92121-2718
This sig uses the word "Exon" in violation of the Communications Decency Act.




  reply	other threads:[~1996-04-05  0:00 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-04-03  0:00 How to print Task_ID type? (GNAT SunOS) Greg Bond
1996-04-04  0:00 ` Robert Dewar
1996-04-04  0:00   ` Greg Bond
1996-04-04  0:00   ` Greg Bond
1996-04-05  0:00     ` Keith Thompson [this message]
1996-04-05  0:00       ` Robert Dewar
1996-04-06  0:00         ` Keith Thompson
1996-04-06  0:00           ` Robert Dewar
1996-04-07  0:00           ` Keith Thompson
1996-04-05  0:00       ` Greg Bond
1996-04-05  0:00     ` Robert Dewar
1996-04-05  0:00   ` Laurent Guerby
1996-04-04  0:00     ` Joel Sherrill
1996-04-06  0:00       ` Fergus Henderson
1996-04-06  0:00         ` Robert Dewar
replies disabled

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