This works:
::cobol
IDENTIFICATION DIVISION.
PROGRAM-ID. prog.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
REPOSITORY.
FUNCTION WITHPAR.
PROCEDURE DIVISION.
DISPLAY WITHPAR(1)
END-DISPLAY
STOP RUN.
END PROGRAM prog.
IDENTIFICATION DIVISION.
FUNCTION-ID. WITHPAR.
DATA DIVISION.
LINKAGE SECTION.
01 PAR-IN PIC 9.
01 PAR-OUT PIC 9.
PROCEDURE DIVISION USING PAR-IN RETURNING PAR-OUT.
ADD 1 TO PAR-IN GIVING PAR-OUT END-ADD.
GOBACK.
END FUNCTION WITHPAR.
while this
::cobol
IDENTIFICATION DIVISION.
PROGRAM-ID. prog.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
REPOSITORY.
FUNCTION WITHPAR.
PROCEDURE DIVISION.
DISPLAY WITHPAR(1)
END-DISPLAY
STOP RUN.
END PROGRAM prog.
IDENTIFICATION DIVISION.
FUNCTION-ID. WITHPAR.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 PAR-OUT PIC 9.
LINKAGE SECTION.
01 PAR-IN PIC 9.
PROCEDURE DIVISION USING PAR-IN RETURNING PAR-OUT.
ADD 1 TO PAR-IN GIVING PAR-OUT END-ADD.
GOBACK.
END FUNCTION WITHPAR.
leads to
prog.c: In function 'WITHPAR_':
prog.c:315:8: error: incompatible types when assigning to type 'unsigned char[1]' from type 'void *'
b_10 = cob_malloc (1U);
^
prog.c: In function 'WITHOUTPAR_':
prog.c:456:8: error: incompatible types when assigning to type 'unsigned char[1]' from type 'void *'
b_17 = cob_malloc (1U);
^
Bugs: #58
Discussion: RETURNING items of User-Defined FUNCTIONs - WORKING-STORAGE or LINKAGE items?
Possible quick fix (not generating cob_malloc) attached. Likely possible that there's a fix with higher performance.
With that patch applied both WORKING-STORAGE and LINKAGE items can be used as RETURNING items for UDFs.
I want to gather some opinions about this issue in general (and the patch) before committing it.
Simon
Last edit: Simon Sobisch 2017-04-10
After additional checks and as pointed out in the discussion at [08d8b633]
RETURNINGitems must be inLINKAGE SECTION. The MF docs show the same rule.Therefore we don't need any change in codegen but in the checks done in the parser.
Related
Discussion: 08d8b633
This bug seems to have been fixed in [r1375].
Roger added a check for this in original 2.0 already, I did not found
out why it wasn't triggered but it is now. I added a bunch of tests in
the testsuite making sure it will be triggered in the future and found
another bug.
I'll close this bug when the testsuite entry is in (next week).
Simon
Testcase is in [1585], additional with the missing check "RETURNING item should have not REDEFINES clause" (which I did not found in the standard but is needed as only "real" fields should be passed).
I realise this is an OLD discussion but I am not sure I understand the resolution.
I am following along some of the examples in the Programmer's Guide and find that the example in the section "11.7 Recursive Subprograms" will not compile because is complains that the RETURNING item is not defined in LINKAGE SECTION.
The code of the example is below as are the compiler error messages. In my eyes either the compiler has a bug or the example in the manual is wrong.
Whch is it please?
Compiler errors for the above code: (Version 3.2)
Last edit: Adrian Hudson 2024-10-23