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?
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With