Menu

libcob: ATE0001:16: Fehler: LINKAGE item »m1t« not passed by caller

Anonymous
2021-05-07
2021-05-12
  • Anonymous

    Anonymous - 2021-05-07

    My problem with r4211 3.2-dev.0.

    The COBOL main program ATE1000

           id division.
           program-id. ATE1000.
           environment division.
           data division.
           working-storage section.
           77  ate  pic xxx  value  'ate'.
           procedure division.
           b00000  section.
               call  'ATE0000'  using  ate
               move  0  to  return-code
               goback
               .
           end program ATE1000.
    

    The C subprogram ATE0000.c

    extern  void ATE0001(
                          int  * const
                         ,char unsigned  []
                        );
    
    extern  void ATE0000(
                          char unsigned  ot[]
                        )
    {
        auto  int  l ;
    
        ATE0001( & l,ot );
    
    }
    

    The COBOL subprogram ATE0001

           id division.
           program-id. ATE0001.
           environment division.
           data division.
           linkage section.
            1  m1l  pic s9(9) comp-5.
            1  m1t  pic xxx.
           procedure division  using  m1l  m1t.
           b00000  section.
               display  m1t
               goback
               .
           end program ATE0001.
    

    ATE1000 abort with

    libcob: ATE0001:16: Fehler: LINKAGE item »m1t« not passed by caller
    
     Last statement of ATE0001 was at line 16 of ATE0001
     Last statement of PCL1887 was at line 15 of ATE1000
    

    Above i removed the directories and the sorces are without comments. The line numbers are correct.
    What is my mistake?

     
    • Simon Sobisch

      Simon Sobisch - 2021-05-07

      The issue here is that your program uses the default COBOL entry-convention which expects a COBOL caller, but the caller was C.

      For the first program You could use cob_call to do the calling (and afterwards likely a cob_cancel - or the combination of both with cob_func).

      For a direct call from a C program you likely just want to adjust the entry-convention. The testsuite (tests/src/syn_misc.at in this case) has one C program that is similar to yours:

      #include <stdio.h>
      #include <libcob.h>  // only used for COB_EXT_EXPORT - not commonly neeeded
      
      COB_EXT_EXPORT int
      cprog (void *cb)
      {
         char *p1;
         int  p2 = 42;
         char *p3 = "CALLBACK";
      
         p1 = p3;
         cob_call_entry (cb, 3, p1, p2, p3);
         return 0;
      }
      

      and the following three different sample programs to show the possibilities you have:

             IDENTIFICATION   DIVISION.
             PROGRAM-ID.      prog.
             OPTIONS.
                 ENTRY-CONVENTION COBOL.
             DATA             DIVISION.
             WORKING-STORAGE  SECTION.
             01 CB            USAGE PROGRAM-POINTER.
             PROCEDURE        DIVISION.
                 SET CB TO ENTRY "callback"
                 CALL STATIC "cprog" USING BY VALUE CB
                 END-CALL
                 EXIT PROGRAM.
             END PROGRAM prog.
      
             IDENTIFICATION   DIVISION.
             PROGRAM-ID.      callback.
             OPTIONS.
                 ENTRY-CONVENTION EXTERN.
             DATA             DIVISION.
             LINKAGE          SECTION.
             01 P1            USAGE POINTER.
             01 P2            USAGE BINARY-LONG.
             01 P3            PIC X(8).
             PROCEDURE        DIVISION USING
                              BY VALUE P1 P2 BY REFERENCE P3.
                 IF P1 NOT EQUAL ADDRESS OF P3
                    DISPLAY P1
                    END-DISPLAY
                 END-IF
                 IF P2 NOT EQUAL 42
                    DISPLAY P2
                    END-DISPLAY
                 END-IF
                 IF P3 NOT EQUAL "CALLBACK"
                    DISPLAY P3
                    END-DISPLAY
                 END-IF
                 EXIT PROGRAM.
      
             IDENTIFICATION   DIVISION.
             PROGRAM-ID.      prog.
             DATA             DIVISION.
             WORKING-STORAGE  SECTION.
             01 CB            USAGE PROGRAM-POINTER.
             PROCEDURE        DIVISION.
                 SET CB TO ENTRY "callback"
                 CALL STATIC "cprog" USING BY VALUE CB
                 END-CALL
                 EXIT PROGRAM.
             END PROGRAM prog.
      
             IDENTIFICATION   DIVISION.
             PROGRAM-ID.      callback.
             DATA             DIVISION.
             LINKAGE          SECTION.
             01 P1            USAGE POINTER.
             01 P2            USAGE BINARY-LONG.
             01 P3            PIC X(8).
             PROCEDURE        DIVISION WITH C LINKAGE
                              USING BY VALUE P1 P2 BY REFERENCE P3.
                 IF P1 NOT EQUAL ADDRESS OF P3
                    DISPLAY P1
                    END-DISPLAY
                 END-IF
                 IF P2 NOT EQUAL 42
                    DISPLAY P2
                    END-DISPLAY
                 END-IF
                 IF P3 NOT EQUAL "CALLBACK"
                    DISPLAY P3
                    END-DISPLAY
                 END-IF
                 EXIT PROGRAM.
      
             IDENTIFICATION   DIVISION.
             PROGRAM-ID.      prog.
             DATA             DIVISION.
             WORKING-STORAGE  SECTION.
             01 CB            USAGE PROGRAM-POINTER.
             PROCEDURE        DIVISION.
                 SET CB TO ENTRY "callback"
                 CALL STATIC "cprog" USING BY VALUE CB
                 END-CALL
                 EXIT PROGRAM.
             END PROGRAM prog.
      
             IDENTIFICATION   DIVISION.
             PROGRAM-ID.      callback.
             ENVIRONMENT DIVISION.
             CONFIGURATION SECTION.
             SPECIAL-NAMES.
                 CALL-CONVENTION 0 IS EXTERN.
             DATA             DIVISION.
             LINKAGE          SECTION.
             01 P1            USAGE POINTER.
             01 P2            USAGE BINARY-LONG.
             01 P3            PIC X(8).
             PROCEDURE        DIVISION EXTERN
                              USING BY VALUE P1 P2 BY REFERENCE P3.
                 IF P1 NOT EQUAL ADDRESS OF P3
                    DISPLAY P1
                    END-DISPLAY
                 END-IF
                 IF P2 NOT EQUAL 42
                    DISPLAY P2
                    END-DISPLAY
                 END-IF
                 IF P3 NOT EQUAL "CALLBACK"
                    DISPLAY P3
                    END-DISPLAY
                 END-IF
                 EXIT PROGRAM.
      

      all compiled with

      cobc --debug -x -Wno-unfinished progN.cob cprog.c

      I guess that helps?

      :-)

      Side note: GnuCOBOL 4.x will have an integrated runtime check for matching entry convention and if the caller is "extern" (= seems to not have been a COBOL program) then auto-adjust from COBOL entry convention to external one) - all those samples will still compile and work fine.

       

      Last edit: Simon Sobisch 2021-05-07
  • Anonymous

    Anonymous - 2021-05-10

    Thank you for the fast answer.

    Please excuse the short description.

    This is a OpenCOBOL (cobol and c) and Enterprise COBOL (cobol and assembler) project with a lot of cobol main and subprogram (n parameter ATE1000) to c (n parameter ATE0000) and c (m parameter ATE0000) to cobol (m parameter ATE0001). OpenCOBOL is okay and GnuCOBOL 3.2 is for me okay if n >= m. The example work fine when i call in ATE0001 with a second dummy parameter in ATE0000 and add a second dummy parameter in ATE0001.

    I prefer the same sources. OpenCOBOL and Enterprise COBOL differs in cobol copies. In the next days i test GnuCOBOL 4.0.

     
    • Simon Sobisch

      Simon Sobisch - 2021-05-10

      Does the source differ only if you use the entry convention? If not Where does they differ and did you actually specified -std=ibm (= what is the exact command line you've used)?

       
  • Anonymous

    Anonymous - 2021-05-12

    On z/OS i use Enterprise COBOL. So the sources differ mainly in file declaration stored in copies. On Linux (and Windows) i use -std=ate. The coding is the same with some if respectively the environment. As attechment my compile/link and ate.conf.

     
    • Simon Sobisch

      Simon Sobisch - 2021-05-12

      Sounds good - but there's no attachment in your post.

      Edit: now found in [1099957f8a]

       

      Related

      Discussion: 1099957f8a


      Last edit: Simon Sobisch 2021-05-12

Anonymous
Anonymous

Add attachments
Cancel