Monday October 23.
We want to test how parameter passing is implemented on various machines
in the GNAT compiler. For this purpose, write a simple program with various
procedures that have in-out parameters. Then call these procedures, using
global variables as actuals. In the body of the procedure, modify the actual,
and check whether the corresponding global variable has been modified. For
each type that you test, print a message indicating whether parameters of
this type are passed by reference, or by value with copy return. Your test
should include scalar parameters (integer, long_float, etc) small records,
large records, small arrays with fixed bounds, and large arrays.
This test depends on aliasing: within a procedure, a given entity is
denoted by some global name, AND by the name of the formal. As we discussed
in class, programs that depend on the exact parameter-passing mechanism in
the presence of aliasing are bad ideas! In this case, though, the purpose is
to learn something about an implementation, and using aliasing is the only
way to do it.
The result of the test is machine-dependent (another reason why real programs
should not depend on this: they are non-portable). The results for composite
types will differ between a Sparc an a Pentium-based machine, for example,
and might differ between Linux and Windows on the same Intel box as well.
If you can easily do this, you might try running your test on two different
targets to see if the results differ.
The test does not require much code: 100 lines plus comments is more than
enough.You should submit the program and its output, indicating on what
machine you ran the test.