I am looking into replacing EQUIVALENCEs with UNIONs. I wrote a little program to test this with a simple example, and it worked just fine. When I looked in the debugger, I could see the two variables of different types which shared memory locations, and when I (or my code) changed one, the other changed accordingly. However, the documentation for UNION says the following:
"With union declarations, only one map declaration within a union declaration can be associated at any point in time with the storage location that they share. Whenever a field within another map declaration in the same union declaration is referenced in your program, the fields in the prior map declaration become undefined and are succeeded by the fields in the map declaration containing the newly referenced field."
This seems to say that the behavior I saw shouldn?t happen. When one variable is changed, the other should become "undefined," presumably meaning that if I were subsequently to refer to it, it would not have a defined value.
Can you explain this for me? My code fragment is as follows:
RECORD /STRUCTURE1/ R
DATA R.C /'ABCD'/
TEMP = R.I(1)
R.I(1) = R.I(2)
R.I(2) = TEMP
PRINT 20, R.C
20 FORMAT(1X,A4) ! Prints 'CDAB'