|
From: | Tim Nixon |
Subject: | [open-cobol-list] CALL USING ADDRESS OF, unsupported |
Date: | Mon Nov 29 10:39:01 2004 |
I believe this is another "IBM Only" issue ADDRESS OF is not supported on a call statement. See
below for code example. Background: As is often the case, there is a need to set a pointer
to the address of a working-storage variable. There is a defined procedure,
SETPTR to do this that you call with the variable and the pointer: i.e.: CALL SETPTR USING VARNAME PTR. (all SETPTR does is SET ptr TO ADDRESS OF varname) Assume there is a LINKAGE SECTION variable, lets call
it LIN1. Also, assume a pointer PTR contains the address of some other
variable. In the code, we can change LIN1 to be an 'alias' for
the other variable like this: SET ADDRESS OF LIN1 TO PTR. (after this, references to LIN1 are to where PTR
pointed) So far all this works, but here's where it gets
interesting.. To set the LINKAGE SECTION variable's address to the
address of a WORKING-STORAGE variable without using a pointer they use: CALL SETPTR USING VARIABLE-NAME ADDRESS OF LIN1. The implication here is that this call to SETPTR can
change the address of LIN1 in the same way it would change a pointers value. It seems like it should work since "ADDRESS
OF" should be compatible with "pointer to" the same item just
like in “c”. Of course that is if ADDRESS OF is supported on a
CALL. As I see it there are 2 issues here. 1) This version of the compiler doesn't support
ADDRESS OF on a call. 2) If ADDRESS OF is to be supported on a CALL, it must
be implemented so that changes made to the address reflect on the original
items address. When CALLing using a pointer, at the c-code level we're really
passing the "address of" the pointer. In the same way, if we use
ADDRESS OF and if we change where the pointer points we really should be
changing the address of the original variable. I dug through the compiler code as well as the C code
resulting from trying this and it seems that to do allow ADDRESS OF on a CALL
like this the code would need to: -create a temp pointer that points to the actual item -CALL using the address of this pointer -upon return from the CALL reset the address of the
original item to be the address stored in the pointer in case the address
changed.. Any thoughts? Tim Nixon |
[Prev in Thread] | Current Thread | [Next in Thread] |