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=-0.8 required=5.0 tests=BAYES_00,INVALID_DATE, MSGID_SHORT autolearn=no autolearn_force=no version=3.4.4 Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!rutgers!ucsd!swrinde!cs.utexas.edu!milano!catalina!bruns From: bruns@catalina.sw.mcc.com (Glenn Bruns) Newsgroups: comp.lang.ada Subject: Ada puzzle Message-ID: <2862@catalina.sw.mcc.com> Date: 7 Sep 89 15:15:59 GMT Organization: MCC, Austin, TX List-Id: 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