Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unprintable integer pointer returned to GNU COBOL from C library

Tags:

c

cobol

gnucobol

I am learning COBOL just for the fun of it and now want to call C functions from my COBOL source (using GnuCOBOL).

I can call C functions just fine, however I have a small problem with a function of mine that looks like this: (It just wraps another function with the same arguments, for now)

int getSensors( char * protocol, int protocolLen,
            char * model, int modelLen,
            int * id, int * dataTypes ) {
    return tdSensor(protocol, protocolLen, model, modelLen, id, dataTypes );
}

My problem is that the value that is returned in the id variable is not printable later in COBOL (TSI-ID below). For example the value returned can be 67, and if I print the variable in COBOL I get the ascii character 'C' instead of the expected value 0067.

The COBOL record looks like this:

   01 TELLSTICK-SENSOR-ITER.
       05 TSI-PROTOCOL     PIC X(50).
       05 TSI-MODEL        PIC X(50).
       05 TSI-ID           PIC 9(4).
       05 TSI-DATATYPES    PIC 9(4).
       05 TSI-RETURN       PIC S9(4).

And my call looks like this:

       CALL "getSensors" USING
           BY REFERENCE TSI-PROTOCOL BY VALUE 50
           BY REFERENCE TSI-MODEL BY VALUE 50
           BY REFERENCE TSI-ID
           BY REFERENCE TSI-DATATYPES
           RETURNING TSI-RETURN.

I'm new to COBOL and my C skills are quite rusty as I usually work in Java. Is there an obvious newbie error in my code here?

like image 880
Deps Avatar asked Oct 22 '16 16:10

Deps


1 Answers

If you return an int you can directly check the RETURN-CODE variable and don't need to use RETURNING clause at all.

If you want to use it: an int maps to retvar USAGE BINARY-LONG.

like image 162
Simon Sobisch Avatar answered Oct 05 '22 04:10

Simon Sobisch