comp.lang.ada
 help / color / mirror / Atom feed
From: adam@irvine.com (Adam Beneschan)
Subject: What does this statement do?
Date: 14 Nov 2001 15:29:01 -0800
Date: 2001-11-14T23:29:01+00:00	[thread overview]
Message-ID: <b4682ab7.0111141529.3598c481@posting.google.com> (raw)

Question for Ada gurus: In the following program, what should happen
with the statement marked HERE?

(a) Z is set to the value of the local variable N
(b) Func is called recursively, and Z is set to the component N of the
    function result
(c) The compiler rejects the statement as ambiguous

				-- thanks, Adam

with Text_IO; use Text_IO;
procedure Test is
    
    type Rectype is record
        M : integer;
        N : integer;
    end record;
    
    Result    : Rectype;
    Recursive : boolean := false;
    
    function Func return Rectype is
        
        N : integer;
        X : integer;
        
        procedure Inner (Z : out integer) is
        begin
            Z := Func.N;        -- <======== HERE
        end Inner;
        
    begin
        N := 1;
        if Recursive then
            return (M => 2, N => 3);
        else
            Recursive := true;
            Inner (X);
            return (M => X, N => X);
        end if;
    end Func;
    
begin
    Result := Func;
    Put_Line (integer'image (Result.M) & ", " & integer'image
(Result.N));
end Test;



             reply	other threads:[~2001-11-14 23:29 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-11-14 23:29 Adam Beneschan [this message]
2001-11-15  7:49 ` What does this statement do? Preben Randhol
2001-11-15 15:32 ` Matthew Heaney
  -- 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