TEAM-ADA Archives

Team Ada: Ada Programming Language Advocacy


Options: Use Forum View

Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Samuel Mize <[log in to unmask]>
Reply To:
Samuel Mize <[log in to unmask]>
Thu, 1 Oct 1998 13:05:12 -0500
text/plain (45 lines)
Scott Edgerton wrote:
  [quoting Michael Feldman]
> For example, if P and Q designate the same value, and you deallocate
> through P, what is the behavior if you try to dereference (access the
> designated block of) Q?
>   Once P has been deallocated, it's value is NULL
>   (ref RM 13.11.2 (7)). Therefore, the value at Q
>   should also be NULL (provided that that storage
>   hasn't been reallocated for something else)
>   Unless I'm missing something?

Sorry, yes, you are.

The value of P is null, but that's the pointer, not the pointed-at
storage space.  Meanwhile, Q (and any other duplicate pointers to
that space) still have their old value -- on some machines this is
now meaningless garbage, on others it still refers to the same
block of memory (which is now available for re-allocation).

>   Perhaps this is why people say that "Ada is hard to learn"...
>   Aliasing (on the surface) seems like a pretty
>   straight forward concept.

Aliasing is a general concept, and is pretty straightforward.  It
means you have two names for the same variable.

In this particular version of aliasing, using pointers, you can
you can have a name that outlives the storage allocation for the
variable.  This is a problem.  It's a common cause, in C, of
hard-to-trace weird behavior and "segmentation fault - core dumped"

Ada's access-value design tries to help the user keep track of
what he's doing.

Sam Mize

Samuel Mize -- [log in to unmask] (home email) -- Team Ada
Fight Spam: see \\\ Smert Spamonam