|
From: | Michael Anderson |
Subject: | Re: [open-cobol-list] Help understanding this behaviour |
Date: | Sun, 01 Sep 2013 20:31:19 -0500 |
User-agent: | Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/20130803 Thunderbird/17.0.8 |
01 some-str PIC X(17) VALUE IS "some" . Also, the above declaration renders a 17 byte character string, containing chars 's', 'o', 'm', 'e', followed by 13 spaces (hex 20). I know the Cobol spec says that when you MOVE "some" to a X(17) string, it is first initialize to spaces, then "some" is strung into the first four bytes. I think the same rule applies to initial value clauses, it shouldn't contain garbage. In scenario #1, "CALL 'stack-controller' USING some-str" The calling program, calls the nested sub, passing some-str by reference (the default), which passes the address of 'some-str' (&some-str), however, oddly, the nested subprogram is using "BY VALUE", on a 32-bit platform the subroutine should receive four bytes containing the address of 'some-str', the results are unpredictable.. For scenario #1, I would remove the "BY VALUE" clause in the nested subroutine, and all should work as expected. In scenario #2, CALL 'stack-controller' USING "some". Calling a subprogram, passing a literal string, like "whatever", then the subroutine should be using the BY VALUE clause, however in this case the length of the string will be an issue, C handles this by using null terminated strings, or by passing an additional item to specify length. You may impliment the same or similar in Cobol, but both routines need to be in cahoots, cooperating. Please read the section in the OpenCobol manual (that Gary wrote) where it explains calling "BY VALUE" and "BY REFERENCE". For scenario #2, make sure the length is negotiated properly, between the caller and the called. Basically, scenario #2: By value makes a copy of the item being passed, and then gives the copy to the subroutine. The calling program will not see any changes made to that item by the called subroutine. scenario #1: By reference passes the address of the callers variable, so when called subroutine is invoked it has access to the exact same variable in the callers working storage, and therefore the called subprogram can make changes and caller will see those changes upon return. -- Mike. On 09/01/2013 07:53 PM, Patrick wrote:
|
[Prev in Thread] | Current Thread | [Next in Thread] |