gnucobol-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [open-cobol-list] CALL USING ADDRESS OF, unsupported


From: William M. Klein
Subject: RE: [open-cobol-list] CALL USING ADDRESS OF, unsupported
Date: Mon Nov 29 21:47:02 2004

I am away from my copy of the '02 Standard.  I believe (but can't swear to
it) that "ADDRESS OF" my be used as a parameter in a CALL statement but ONLY
"BY CONTENT" (i.e. the subroutine may NOT modify it).

IBM definitely allows it BY REFERENCE - see:
 
http://publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/BOOKS/IGY3LR20/6.2.4.2 

However, if you also look at:
  http://publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/BOOKS/igy3pg20/4.2.1 

It ONLY talks about using ADDRESS OF with BY CONTENT and BY VALUE - and
explicitly says that changes in the subprogram do NOT impact the address in
the calling program.  

My *guess* is that either there is an error in the LRM or "results are
unpredictable" when you pass an ADDRESS OF by REFERENCE.

NOTE: the section in the programming guide have "change bars" which makes me
think it is most current.


________________________________

From: address@hidden
[mailto:address@hidden On Behalf Of Tim Nixon
Sent: Monday, November 29, 2004 11:38 AM
To: address@hidden
Subject: [open-cobol-list] CALL USING ADDRESS OF, unsupported



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





reply via email to

[Prev in Thread] Current Thread [Next in Thread]