access type referencing nested array element 
Author Message
 access type referencing nested array element

Greetings,

Anyone know the syntax for referencing an array element (record) from an
access type pointing to an array of records ?

pointer -> array of records -> record

type xyz_rec is
    record
      a : integer;
      b : integer;
    end record;

type xyz_array is array (1 .. 100) of xyz_rec;
type xyz_pointer is access xyz_array;

Here is my guess assuming that I want to get the 5th record in an array:
XYZ    :  xyz_pointer;
MY_XYZ :  xyz_rec;

assuming that the pointer XYZ has been assigned to an array of records .....

MY_XYZ := XYZ.xyz_array'(5);  or maybe

MY_XYZ := XYZ.xyz_array'(5).all;     or maybe I'm just guessing too much.

help..........

Thanks,
Richmond



Wed, 07 Mar 2001 03:00:00 GMT  
 access type referencing nested array element

Quote:

> Anyone know the syntax for referencing an array element (record) from an
> access type pointing to an array of records ?

   XYZ (5).a -- implicit dereferencing
   XYZ.all (5).a -- explicit dereferencing

Dale



Wed, 07 Mar 2001 03:00:00 GMT  
 access type referencing nested array element
Greetings Dale,

Quote:
> > Anyone know the syntax for referencing an array element (record) from an
> > access type pointing to an array of records ?

>    XYZ (5).a -- implicit dereferencing
>    XYZ.all (5).a -- explicit dereferencing

> Dale

Ok, that means that if XYZ is a pointer to array of records, I can simply
use the pointer with the array index eg. (5) to access the 5th record.
Now if I want to get the address of the 5th record would this be correct:

type xyz is access xyz_rec;

XYZ_POINTER := XYZ (5)'access;

????

thanks.
Richmond



Wed, 07 Mar 2001 03:00:00 GMT  
 access type referencing nested array element

: Ok, that means that if XYZ is a pointer to array of records, I can simply
: use the pointer with the array index eg. (5) to access the 5th record.
: Now if I want to get the address of the 5th record would this be correct:

: type xyz is access xyz_rec;

: XYZ_POINTER := XYZ (5)'access;

Yes, presuming the array is declared an an array of *aliased* components.

E.g.:

   type array_of_rec is array(Positive range <>) of aliased xyz_rec;
                                                    ^^^^^^^
                     This is required if you want to use 'Access.

: ????

: thanks.
: Richmond

--

Intermetrics, Inc.  Burlington, MA  USA
An AverStar Company



Wed, 07 Mar 2001 03:00:00 GMT  
 access type referencing nested array element
I responded earlier:

: : Ok, that means that if XYZ is a pointer to array of records, I can simply
: : use the pointer with the array index eg. (5) to access the 5th record.
: : Now if I want to get the address of the 5th record would this be correct:

: : type xyz is access xyz_rec;
                     ^^^ insert "all" here

: : XYZ_POINTER := XYZ (5)'access;

: Yes, presuming the array is declared an an array of *aliased* components.

As indicated above, I forgot to mention that you need to say
"access all" rather than simply "access" if you want to use 'Access
to create values of your access type.  Without the "all", you can
only use an allocator (new xyz_rec...) to create values of your
access type.

: E.g.:

:    type array_of_rec is array(Positive range <>) of aliased xyz_rec;
:                                                     ^^^^^^^
:                      This is required if you want to use 'Access.

: : ????

: : thanks.
: : Richmond

--

Intermetrics, Inc.  Burlington, MA  USA
An AverStar Company



Wed, 07 Mar 2001 03:00:00 GMT  
 access type referencing nested array element

Quote:

> In particular, the horrible phenomenon of people importing
> a C style into Ada 95 is something I often see, with the
> aliased keyword all over the place. Perfectly dreadful
> coding style!

I suspect that you wouldn't like the C++ STL, or the Ada translations of
it, since they tend to use "aliased" a lot (in the Ada case of course; in
C++ everything is potentially aliased) and I think you couldn't write an
STL in Ada without it. I agree completely with your admonition against its
(over)use, but I'm awfully glad its there.

-- Brian



Wed, 07 Mar 2001 03:00:00 GMT  
 access type referencing nested array element

Quote:
Robert Dewar wrote...

" In particular, the horrible phenomenon of people importing
  a C style into Ada 95 is something I often see, with the
  aliased keyword all over the place. Perfectly dreadful
  coding style!"

But of course a better style is to silenty do a 'Unrestricted_Access
deep inside your code (a'la Gnat.Spitbol :-)

Dale



Thu, 08 Mar 2001 03:00:00 GMT  
 
 [ 9 post ] 

 Relevant Pages 

1. Access Array Elements by Arrays Reference

2. HOWTO: reference elements of an array if array name is in a variable

3. member types and array-element-type?

4. (typep (make-array 10 :element-type 'bit) '(array bit (10)))

5. Shifting array element & regex on array element

6. Reference to derived type element by index?

7. Passing array elements by reference

8. Return value that is an access to array element

9. Accessing array elements.

10. UPGRADED-ARRAY-ELEMENT-TYPE

11. The set of specialized array element types must be closed under intersection

12. (upgraded-array-element-type nil)

 

 
Powered by phpBB® Forum Software