comp.lang.ada
 help / color / mirror / Atom feed
* access assignation. Aliasing problems?
@ 2008-02-01 10:01 Javi
  2008-02-01 14:02 ` Robert A Duff
  2008-02-01 18:24 ` Jeffrey R. Carter
  0 siblings, 2 replies; 5+ messages in thread
From: Javi @ 2008-02-01 10:01 UTC (permalink / raw)


Hi again, I have some problem between access assignations. "List" has
in its definition a private access to ListNode (First, Last). Why
can't I do the assignation: L.List := L.Last ? it does produce an
"accessibilty error check". If both values are null, I can not either
do the assignation.

-----------
...
   procedure putItem (L : in out List; It : in ItemList) is
   begin
      if L.Last = null then
         L.Last := new ListNode'(Item => It, next => null);
         print(L.Last.Item); --DBG this prints OK, the Item was
properly assigned
         L.First := L.Last; -- this fails, L.First and L.Last are both
the same type access ListNode
...
----------


I'm very sorry because of bothering you with this simple questions,
thanks again.



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

* Re: access assignation. Aliasing problems?
  2008-02-01 10:01 access assignation. Aliasing problems? Javi
@ 2008-02-01 14:02 ` Robert A Duff
  2008-02-01 18:24 ` Jeffrey R. Carter
  1 sibling, 0 replies; 5+ messages in thread
From: Robert A Duff @ 2008-02-01 14:02 UTC (permalink / raw)


Javi <fjvera@gmail.com> writes:

> Hi again, I have some problem between access assignations. "List" has
> in its definition a private access to ListNode (First, Last). Why
> can't I do the assignation: L.List := L.Last ? it does produce an
> "accessibilty error check". If both values are null, I can not either
> do the assignation.
>
> -----------
> ...
>    procedure putItem (L : in out List; It : in ItemList) is
>    begin
>       if L.Last = null then
>          L.Last := new ListNode'(Item => It, next => null);
>          print(L.Last.Item); --DBG this prints OK, the Item was
> properly assigned
>          L.First := L.Last; -- this fails, L.First and L.Last are both
> the same type access ListNode
> ...
> ----------
>
>
> I'm very sorry because of bothering you with this simple questions,
> thanks again.

No need to apologize -- your question is a reasonable one.  But you're
more likely to get an answer if you post a complete compilable example,
and explain in detail what "this fails" means.

- Bob



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

* Re: access assignation. Aliasing problems?
  2008-02-01 10:01 access assignation. Aliasing problems? Javi
  2008-02-01 14:02 ` Robert A Duff
@ 2008-02-01 18:24 ` Jeffrey R. Carter
  2008-02-02 10:37   ` Stephen Leake
  1 sibling, 1 reply; 5+ messages in thread
From: Jeffrey R. Carter @ 2008-02-01 18:24 UTC (permalink / raw)


Javi wrote:
>          L.Last := new ListNode'(Item => It, next => null);
>          L.First := L.Last; -- this fails, L.First and L.Last are both
> the same type access ListNode

I suspect you're saying that type List has components such as

type List is record
    First : access Listnode;
    Last  : access Listnode;
    ...
end record;

The solution is simple: Don't use anonymous types. Use a named type instead:

type Node_Ptr is access Listnode; -- Using '_' is The Ada Way.

type List is record
    First : Node_Ptr;
    Last  : Node_Ptr;
    ...
end record;

Anonymous types are a horrible thing and should be avoided whenever possible.

-- 
Jeff Carter
"Sir Robin the-not-quite-so-brave-as-Sir-Lancelot,
who had nearly fought the Dragon of Angnor,
who nearly stood up to the vicious Chicken of Bristol,
and who had personally wet himself at the
Battle of Badon Hill."
Monty Python & the Holy Grail
68



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

* Re: access assignation. Aliasing problems?
  2008-02-01 18:24 ` Jeffrey R. Carter
@ 2008-02-02 10:37   ` Stephen Leake
  2008-02-02 21:02     ` Javi
  0 siblings, 1 reply; 5+ messages in thread
From: Stephen Leake @ 2008-02-02 10:37 UTC (permalink / raw)


"Jeffrey R. Carter" <spam.jrcarter.not@acm.nospam.org> writes:

> Javi wrote:
>>          L.Last := new ListNode'(Item => It, next => null);
>>          L.First := L.Last; -- this fails, L.First and L.Last are both
>> the same type access ListNode
>
> I suspect you're saying that type List has components such as
>
> type List is record
>     First : access Listnode;
>     Last  : access Listnode;

In particular, these are _not_ the "same type". In C, they would be,
because there "same type" means "same contents". In Ada, "same type"
means "same name". The types here have _no_ name; they are
anonymous. So they are not the same.

-- 
-- Stephe



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

* Re: access assignation. Aliasing problems?
  2008-02-02 10:37   ` Stephen Leake
@ 2008-02-02 21:02     ` Javi
  0 siblings, 0 replies; 5+ messages in thread
From: Javi @ 2008-02-02 21:02 UTC (permalink / raw)


On Feb 2, 11:37 am, Stephen Leake <stephen_le...@stephe-leake.org>
wrote:
> "Jeffrey R. Carter" <spam.jrcarter....@acm.nospam.org> writes:
>
> > Javi wrote:
> >>          L.Last := new ListNode'(Item => It, next => null);
> >>          L.First := L.Last; -- this fails, L.First and L.Last are both
> >> the same type access ListNode
>
> > I suspect you're saying that type List has components such as
>
> > type List is record
> >     First : access Listnode;
> >     Last  : access Listnode;
>
> In particular, these are _not_ the "same type". In C, they would be,
> because there "same type" means "same contents". In Ada, "same type"
> means "same name". The types here have _no_ name; they are
> anonymous. So they are not the same.
>
> --
> -- Stephe


Many thanks guys, as I said, I'm quiet new to Ada. I'm used to C
pointers :-)

Thanks a lot !



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

end of thread, other threads:[~2008-02-02 21:02 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-02-01 10:01 access assignation. Aliasing problems? Javi
2008-02-01 14:02 ` Robert A Duff
2008-02-01 18:24 ` Jeffrey R. Carter
2008-02-02 10:37   ` Stephen Leake
2008-02-02 21:02     ` Javi

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