Print

Print


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"
failures.

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

Best,
Sam Mize

--
Samuel Mize -- [log in to unmask] (home email) -- Team Ada
Fight Spam: see http://www.cauce.org/ \\\ Smert Spamonam