comp.lang.ada
 help / color / mirror / Atom feed
From: "Matthew Heaney" <mheaney@on2.com>
Subject: Re: What does this statement do?
Date: Thu, 15 Nov 2001 10:32:26 -0500
Date: 2001-11-15T10:32:26-05:00	[thread overview]
Message-ID: <tv7npq5998ob79@corp.supernews.com> (raw)
In-Reply-To: b4682ab7.0111141529.3598c481@posting.google.com


"Adam Beneschan" <adam@irvine.com> wrote in message
news:b4682ab7.0111141529.3598c481@posting.google.com...
> Question for Ada gurus: In the following program, what should happen
> with the statement marked HERE?
> (c) The compiler rejects the statement as ambiguous

What did you expect to happen?  The name N can mean the N component of the
Rectype object returned by Func, or it can mean the local variable N.  The
compiler is correct.

Applying the selection operator to a function return has a long tradition in
Ada; this is an especially important idiom since Ada doesn't have explicit
reference types a la C++.

For example, this is how you implement a stack (or whatever) whose items are
limited:

generic
   type Item_Type is limited private;
package Stacks is
   type Stack_Type is limited private;

   type Item_Access is access all Item_Type;
   for Item_Access'Storage_Size use 0;

   procedure Push (Stack : in out Stack_Type);

   function Get_Top (Stack : access Stack_Type) return Item_Access;
...
end;

You'd use it like this:

declare
   S : aliased Stack_Type;
begin
   Push (S);

   declare
      Item : Some_Limited_Type renames Get_Top (S'Access).all;
   begin
      Do_Something (Item);
   end;
end;

I few days ago I used a similar technique that showed how to implement
Java-style interfaces in Ada95.







  parent reply	other threads:[~2001-11-15 15:32 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-11-14 23:29 What does this statement do? Adam Beneschan
2001-11-15  7:49 ` Preben Randhol
2001-11-15 15:32 ` Matthew Heaney [this message]
  -- strict thread matches above, loose matches on Subject: below --
2001-11-15 13:45 Gautier Write-only-address
replies disabled

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