comp.lang.ada
 help / color / mirror / Atom feed
From: dewarr@my-dejanews.com
Subject: Re: access type referencing nested array element
Date: 1998/09/19
Date: 1998-09-19T00:00:00+00:00	[thread overview]
Message-ID: <6u0fmj$hlm$1@nnrp1.dejanews.com> (raw)
In-Reply-To: EzJ5Gp.JG5.0.-s@inmet.camb.inmet.com

In article <EzJ5Gp.JG5.0.-s@inmet.camb.inmet.com>,
  stt@houdini.camb.inmet.com (Tucker Taft) wrote:
> Technobabble (WishList@2600.com) wrote:
>
> : 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.
>


Indeed, and that helps explain why I advise not using the
access attribute AT ALL. Aliasing is in general a bad thing.
General pointers were excluded from Ada 83 for very good
reasons. They were added in Ada 95 for good, but very narrow
reasons (the most convincing argument was the need to be
able to statically initialize structures containing pointers)

BUT! Once this features is there it is subject to horrible
misuse. I find the undisciplined use of pointers and access
to be the data analog of gotos. As you all know, I don't have
a rule that absolutely forbids gotos, and I do not suggest a
rule that absolutely forbids the use of access. Indeed any
rule that absolutely forbids the use of any feature in Ada
is highly suspect (every feature in Ada was put there for a
purpose, if you think a given feature is so useless that it
should never be used, you are probably missing something).

However, just as we teach students never to use goto, so
that they can discover how to properly strucure programs
in the usual case, we should teach them never to use 'Access
so they can learn how to properly structure their data in
the usual case.

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!

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum




  reply	other threads:[~1998-09-19  0:00 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-09-19  0:00 access type referencing nested array element Technobabble
1998-09-19  0:00 ` Dale Stanbrough
1998-09-19  0:00   ` Technobabble
1998-09-19  0:00     ` Tucker Taft
1998-09-19  0:00       ` dewarr [this message]
1998-09-19  0:00         ` Brian Rogoff
1998-09-20  0:00           ` Dale Stanbrough
1998-09-20  0:00             ` dewarr
1998-09-19  0:00       ` Tucker Taft
replies disabled

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