comp.lang.ada
 help / color / mirror / Atom feed
* Re: Access type conversion...
       [not found] <mbejeranD2Hn5E.q5@netcom.com>
@ 1995-01-18 18:51 ` R. William Beckwith
  1995-01-19  9:21 ` Whitteng
  1995-01-20  0:12 ` Garlington KE
  2 siblings, 0 replies; 4+ messages in thread
From: R. William Beckwith @ 1995-01-18 18:51 UTC (permalink / raw)


Marc J Bejerano (mbejeran@netcom.com) wrote:
: I have a question regarding access types. In my application, I have a data
: type which is a string pointer (Type PString is Access String) and a system
: address pointer (tempAddr : System.Address).

: How do I equate the general purpose System.Address to the PString?

Assume:

    String_Ptr : PString := new string'("Hello" & Ascii.Nul);

from String_Ptr to System.Address:

    tempAddr   : System.Address := String_Ptr(String_Ptr'FIRST)'ADDRESS;

from System.Address to String_Ptr:

    Don't.  It won't be portable.

... Bill



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

* Re: Access type conversion...
       [not found] <mbejeranD2Hn5E.q5@netcom.com>
  1995-01-18 18:51 ` Access type conversion R. William Beckwith
@ 1995-01-19  9:21 ` Whitteng
  1995-01-20  8:59   ` Keith Thompson
  1995-01-20  0:12 ` Garlington KE
  2 siblings, 1 reply; 4+ messages in thread
From: Whitteng @ 1995-01-19  9:21 UTC (permalink / raw)


Fisrt of all I have to ask, "Are you thinking like a C programmer?". 
Shame, shame!

A System.Address does not have to be the same thing as an access type.  On
some compilers they are not even the same size (e.g. System.Address is
4-bytes while access types are only 2-bytes).  In all of the work we do we
require System.Address and access types to be the same size.

The others have shown examples of how to get the string's address.  Our
standard way of getting the address of the first element of an array is

     addr := array(array'first)'address;

This works and seems to be the most portable.  Something like

     addr := array'address,

does not have to give you the address of the array's first element, it has
to give you the address of the first storage allocation unit the array
uses.  This may be a hidden data area that contains info about the array
(e.g. first, last).

There is really not much you can do with the address to the array in Ada,
but we find it quite usefull when interfacing with a library that may have
been written in assembler or C.

TTFN < ; - | )



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

* Re: Access type conversion...
       [not found] <mbejeranD2Hn5E.q5@netcom.com>
  1995-01-18 18:51 ` Access type conversion R. William Beckwith
  1995-01-19  9:21 ` Whitteng
@ 1995-01-20  0:12 ` Garlington KE
  2 siblings, 0 replies; 4+ messages in thread
From: Garlington KE @ 1995-01-20  0:12 UTC (permalink / raw)


Marc J Bejerano (mbejeran@netcom.com) wrote:
: I have a question regarding access types. In my application, I have a data
: type which is a string pointer (Type PString is Access String) and a system
: address pointer (tempAddr : System.Address).

: How do I equate the general purpose System.Address to the PString?

As already mentioned, this is dangerous and compiler-dependent. However,
depending upon how the compiler stores data, _sometimes_ you can do
one of the following: (1) do an unchecked_conversion to load the system.address
into the PString object, or (2) do an unchecked_conversion of system.address,
adjusted by some value to compensate for the dynamic bounds of the string
being stored before the string itself, into the Pstring object.

If the real requirement is to be able to declare access objects that
reference strings, without forcing those strings to be allocated via "new",
then get an Ada95 compiler ASAP that implements the improved access mechanisms.
Life will be much simpler.

: -Marc

: P.S. Thanks for your patience.

--
--------------------------------------------------------------------
Ken Garlington                  GarlingtonKE@lfwc.lockheed.com
F-22 Computer Resources         Lockheed Fort Worth Co.

If LFWC or the F-22 program has any opinions, they aren't telling me.



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

* Re: Access type conversion...
  1995-01-19  9:21 ` Whitteng
@ 1995-01-20  8:59   ` Keith Thompson
  0 siblings, 0 replies; 4+ messages in thread
From: Keith Thompson @ 1995-01-20  8:59 UTC (permalink / raw)


In <3flau7$bgu@newsbf02.news.aol.com> whitteng@aol.com (Whitteng) writes:
> The others have shown examples of how to get the string's address.  Our
> standard way of getting the address of the first element of an array is
> 
>      addr := array(array'first)'address;
> 
> This works and seems to be the most portable.

Don't forget that this will raise Constraint_Error if the array has a
length of 0.

In the most common case, interfacing to C, this probably won't be a
problem; most C functions that take strings require at least a NUL
character.

-- 
Keith Thompson (The_Other_Keith)  kst@thomsoft.com (kst@alsys.com still works)
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
When you're a nail, every problem looks like a hammer.



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

end of thread, other threads:[~1995-01-20  8:59 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <mbejeranD2Hn5E.q5@netcom.com>
1995-01-18 18:51 ` Access type conversion R. William Beckwith
1995-01-19  9:21 ` Whitteng
1995-01-20  8:59   ` Keith Thompson
1995-01-20  0:12 ` Garlington KE

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