comp.lang.ada
 help / color / mirror / Atom feed
* Get a pointer to an array
@ 1999-06-05  0:00 Elad Rosenheim
  1999-06-06  0:00 ` David Botton
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Elad Rosenheim @ 1999-06-05  0:00 UTC (permalink / raw)


This question may seem easy, but I haven't been able to find
a solution:

How do I create a normal array, then point an access type to it?
I tried to convert the array 'address attribute to the array access
type,
but it didn't work. I think ADA arrays have some "meta data" before
the data that contains the array bounds, and the 'address attribute
gives the address of the data storage itself. So how can I make the
access
variable point to the array?

This doesn't work:

    type int_array is array(integer <>) of integer;
    type int_access is access int_array;

    function To_Int_Access is new Unchecked_Conversion(
	system.address, int_access);
...

declare
    a : int_array(1..10);
    b : int_access;
begin
    a :=  To_Int_Access(a'address);
...

Please help me with this one.

Thanks,
Elad Rosenheim.




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

* Re: Get a pointer to an array
  1999-06-05  0:00 Get a pointer to an array Elad Rosenheim
  1999-06-06  0:00 ` David Botton
@ 1999-06-06  0:00 ` Robert Dewar
  1999-06-09  0:00 ` Steve Doiel
  2 siblings, 0 replies; 4+ messages in thread
From: Robert Dewar @ 1999-06-06  0:00 UTC (permalink / raw)


In article <37599022.C77585D@barak-online.net>,
  Elad Rosenheim <e_ros@netvision.net.il> wrote:
> This question may seem easy, but I haven't been able to find
> a solution:
>
> How do I create a normal array, then point an access type to
> it?

First answer, Don't! Aliasing of this kind is almost always
dubious and inadvisable.

Second answer, if you must do it for a good reason (there are
not very many good reasons for doing this), then declare the
array aliased, and use 'Access.



Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.




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

* Re: Get a pointer to an array
  1999-06-05  0:00 Get a pointer to an array Elad Rosenheim
@ 1999-06-06  0:00 ` David Botton
  1999-06-06  0:00 ` Robert Dewar
  1999-06-09  0:00 ` Steve Doiel
  2 siblings, 0 replies; 4+ messages in thread
From: David Botton @ 1999-06-06  0:00 UTC (permalink / raw)


You take the access/address of the first element.
a(1)'address or a(1)'access in your code.

And to get back from an address/access to an array you should use the
Interfaces.C.Pointers generic package. (see
http://www.adapower.com/os/com-bstr.html for an example of using
Interfaces.C.Pointers)

Also not if you are trying to work with C:

RM B.3:70

An Ada parameter of an array type with component type T, of any mode, is
passed as a t* argument to a C function, where t is the C type
corresponding to the Ada type T.


David Botton


Elad Rosenheim wrote:
> 
> This question may seem easy, but I haven't been able to find
> a solution:
> 
> How do I create a normal array, then point an access type to it?
> I tried to convert the array 'address attribute to the array access
> type,
> but it didn't work. I think ADA arrays have some "meta data" before
> the data that contains the array bounds, and the 'address attribute
> gives the address of the data storage itself. So how can I make the
> access
> variable point to the array?
> 
> This doesn't work:
> 
>     type int_array is array(integer <>) of integer;
>     type int_access is access int_array;
> 
>     function To_Int_Access is new Unchecked_Conversion(
>         system.address, int_access);
> ...
> 
> declare
>     a : int_array(1..10);
>     b : int_access;
> begin
>     a :=  To_Int_Access(a'address);
> ...
> 
> Please help me with this one.
> 
> Thanks,
> Elad Rosenheim.




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

* Re: Get a pointer to an array
  1999-06-05  0:00 Get a pointer to an array Elad Rosenheim
  1999-06-06  0:00 ` David Botton
  1999-06-06  0:00 ` Robert Dewar
@ 1999-06-09  0:00 ` Steve Doiel
  2 siblings, 0 replies; 4+ messages in thread
From: Steve Doiel @ 1999-06-09  0:00 UTC (permalink / raw)


>How do I create a normal array, then point an access type to it?
>I tried to convert the array 'address attribute to the array access
>type,
>but it didn't work. I think ADA arrays have some "meta data" before
>the data that contains the array bounds, and the 'address attribute
>gives the address of the data storage itself. So how can I make the
>access
>variable point to the array?
>
Is this what you're looking for?

procedure question is

type int_array is array(integer range <>) of integer;
type int_access is access all int_array;

a : aliased int_array := (1..10 => 0);
b : int_access;

begin
  b := a'access;
end question;







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

end of thread, other threads:[~1999-06-09  0:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-06-05  0:00 Get a pointer to an array Elad Rosenheim
1999-06-06  0:00 ` David Botton
1999-06-06  0:00 ` Robert Dewar
1999-06-09  0:00 ` Steve Doiel

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