comp.lang.ada
 help / color / mirror / Atom feed
From: bruns@catalina.sw.mcc.com (Glenn Bruns)
Subject: Ada puzzle
Date: 7 Sep 89 15:15:59 GMT	[thread overview]
Message-ID: <2862@catalina.sw.mcc.com> (raw)

Given the text for an arbitrary Ada procedure, and assuming that all
variables within the procedure are either local variables of the
procedure or parameters of the procedure, is it possible to make a
copy of any variable within the procedure?  By "make a copy", I mean
to create a new variable with the same value as the original variable
that can be used in exactly the same way as the original variable.
Note that no type information is available except as found in the
text of the procedure.

If the variable is a local variable of the procedure, the problem
does not seem too hard.  Consider the following procedure:

    procedure FOO is
	X : INT_ARRAY(1 .. 3) := (4, 5, 6);
	I : INTEGER;
    begin
	I := X(1);  
    end FOO;

This version of FOO contains code to copy X to new variable Y:

    procedure FOO is
	X : INT_ARRAY(1 .. 3) := (4, 5, 6);
	I : INTEGER;
	Y : INT_ARRAY(1 .. 3);
    begin
	Y := X;
	I := Y(1); 
    end FOO;

But what if the variable to be copied is a parameter of the procedure?

    procedure BAR(X : in SOME_TYPE; Z : out SOME_TYPE) is
    begin
	Z := X;
    end BAR;

It does not seem that I know enough about the type of X here to be
able to create a new variable Y that is a copy of X.  The naive
solution is:

    procedure BAR(X : in SOME_TYPE; Z : out SOME_TYPE) is 
	Y : SOME_TYPE;
    begin
	Y := X;
        Z := Y;	
    end BAR;

But this doesn't work when, for example, SOME_TYPE is an
unconstrained array type.  There are ways to copy X if SOME_TYPE _is_
an unconstrained array type, but these techniques don't work for all
types.


-- 
Glenn Bruns 
MCC, Software Technology Program
arpa: bruns@mcc.com    
uucp: {seismo,harvard,gatech,pyramid}!ut-sally!im4u!milano!bruns

             reply	other threads:[~1989-09-07 15:15 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1989-09-07 15:15 Glenn Bruns [this message]
1989-09-07 17:02 ` Ada puzzle hagerp
replies disabled

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