From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,af291903d8d84b0c X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-11-15 07:28:58 PST Path: archiver1.google.com!news1.google.com!sn-xit-02!sn-post-02!sn-post-01!supernews.com!corp.supernews.com!not-for-mail From: "Matthew Heaney" Newsgroups: comp.lang.ada Subject: Re: What does this statement do? Date: Thu, 15 Nov 2001 10:32:26 -0500 Organization: Posted via Supernews, http://www.supernews.com Message-ID: References: X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4807.1700 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4807.1700 X-Complaints-To: newsabuse@supernews.com Xref: archiver1.google.com comp.lang.ada:16570 Date: 2001-11-15T10:32:26-05:00 List-Id: "Adam Beneschan" 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.