Menu

#57 RETURNING item must be in LINKAGE SECTION (check missing)

GC 2.2
closed
None
4
2024-10-23
2014-01-02
No

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);
        ^
1 Attachments

Related

Bugs: #58
Discussion: RETURNING items of User-Defined FUNCTIONs - WORKING-STORAGE or LINKAGE items?

Discussion

  • Simon Sobisch

    Simon Sobisch - 2014-01-02

    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

     
  • Simon Sobisch

    Simon Sobisch - 2014-01-02
    • assigned_to: Simon Sobisch
     
  • Simon Sobisch

    Simon Sobisch - 2014-11-24
    • Group: unclassified --> GC 2.0
    • Priority: 1 --> 5
     
  • Simon Sobisch

    Simon Sobisch - 2017-04-10
    • summary: UDF: C compiler error if RETURNING items are part of WORKING STORAGE --> RETURNING item must be in LINKAGE SECTION (check missing)- status: open --> accepted
    • Priority: 5 --> 4
     

    Last edit: Simon Sobisch 2017-04-10
  • Simon Sobisch

    Simon Sobisch - 2017-04-10

    After additional checks and as pointed out in the discussion at [08d8b633] RETURNING items must be in LINKAGE 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

  • Edward Hart

    Edward Hart - 2017-04-22

    This bug seems to have been fixed in [r1375].

     
    • Simon Sobisch

      Simon Sobisch - 2017-04-22

      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

       
  • Simon Sobisch

    Simon Sobisch - 2017-05-07
    • status: accepted --> closed
    • Group: 2.2 --> GC 2.2
     
  • Simon Sobisch

    Simon Sobisch - 2017-05-07

    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).

     
  • Adrian Hudson

    Adrian Hudson - 2024-10-23

    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?

            IDENTIFICATION DIVISION.
            PROGRAM-ID. DEMOFACT.
            ENVIRONMENT DIVISION.
            CONFIGURATION SECTION.
            REPOSITORY.
                FUNCTION RECURSIVEFUNC.
            DATA DIVISION.
            WORKING-STORAGE SECTION.
            01 Result USAGE BINARY-LONG.
            01 Arg    USAGE BINARY-LONG.
            PROCEDURE DIVISION.
            000-Main.
                MOVE 6 TO Arg
                CALL "RECURSIVESUB"
                    USING BY CONTENT Arg
                    RETURNING Result
                DISPLAY Arg "! = "
                    Result
                DISPLAY Arg "! = "
                    RECURSIVEFUNC(Arg)
                GOBACK
                .
            END PROGRAM DEMOFACT.
    
    
            IDENTIFICATION DIVISION.
            PROGRAM-ID. SUB RECURSIVE.
            DATA DIVISION.
            WORKING-STORAGE SECTION.
            01 Result       USAGE BINARY-LONG.
            01 Next-Arg     USAGE BINARY-LONG.
            01 Next-Result  USAGE BINARY-LONG.
            LINKAGE SECTION.
            01 Arg          USAGE BINARY-LONG.
            PROCEDURE DIVISION USING Arg
                RETURNING Result.
            000-Main.
                DISPLAY "Entering SUB"
                " Arg=" Arg
                IF Arg = 1
                MOVE 1 TO Result
                DISPLAY "Leaving SUB"
                   " Returning " Result
                ELSE
                SUBTRACT 1 FROM Arg
                GIVING Next-Arg
                CALL "SUB"
                    USING BY CONTENT Next-Arg
                    RETURNING Next-Result
                COMPUTE Result =
                    Arg * Next-Result
                DISPLAY "Leaving SUB"
                        " Returning "
                        Result "=" Arg "*"
                        Next-Result
                END-IF
                GOBACK
                .
            END PROGRAM SUB.
    
            IDENTIFICATION DIVISION.
            FUNCTION-ID. FUNC.
            ENVIRONMENT DIVISION.
            CONFIGURATION SECTION.
                REPOSITORY.
            FUNCTION RECURSIVEFUNC.
            DATA DIVISION.
            WORKING-STORAGE SECTION.
            LINKAGE SECTION.
            01 Arg USAGE BINARY-LONG.
            01 Result USAGE BINARY-LONG
                SIGNED.
            PROCEDURE DIVISION USING Arg
                RETURNING Result.
            000-Main.
                DISPLAY "Entering FUNC"
                        " Arg=" Arg
                IF Arg = 1
                    MOVE 1 TO Result
                ELSE
                    COMPUTE Result = Arg *
                            FUNC(Arg - 1)
                END-IF
                DISPLAY "Leaving FUNC"
                        " Returning " Result
                GOBACK
                .
            END FUNCTION FUNC.
    

    Compiler errors for the above code: (Version 3.2)

    cobc DEMOFACT.cbl
    DEMOFACT.cbl:36: error: RETURNING item is not defined in LINKAGE SECTION
       34 |         01 Arg          USAGE BINARY-LONG.
       35 |         PROCEDURE DIVISION USING Arg
       36 >             RETURNING Result.
       37 |         000-Main.
       38 |             DISPLAY "Entering SUB"
    DEMOFACT.cbl: in paragraph '000-Main':
    DEMOFACT.cbl:49: warning: unexpected RETURNING item [-Wrepository-checks]
       47 |             CALL "SUB"
       48 |                 USING BY CONTENT Next-Arg
       49 >                 RETURNING Next-Result
       50 |             COMPUTE Result =
       51 |                 Arg * Next-Result
    
     

    Last edit: Adrian Hudson 2024-10-23

Log in to post a comment.

MongoDB Logo MongoDB