PROGRAM-ID. BUG.
AUTHOR. Andrejs Lubimovs.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 VAR-IN-MEMORY PIC X(100).
01 PTR-TO-VAR POINTER.
LINKAGE SECTION.
01 PTR POINTER.
PROCEDURE DIVISION.
SET PTR-TO-VAR TO ADDRESS OF VAR-IN-MEMORY
CALL 'CALL-USING-PTR' USING BY VALUE PTR-TO-VAR
CALL 'CALL-USING-PTR' USING BY VALUE ADDRESS OF VAR-IN-MEMORY
GOBACK
.
ENTRY 'CALL-USING-PTR'
USING
BY VALUE
PTR
DISPLAY "Pointer value: " PTR
GOBACK
.
END PROGRAM BUG.
System description where code compiled:
Ubuntu 16.10 x86_64 (latest updates installed);
gcc (Ubuntu 6.2.0-5ubuntu12) 6.2.0 20161005gcc (Ubuntu 6.2.0-5ubuntu12) 6.2.0 20161005;
I compiled example above using cobc -x -std=mf bug.cob I got warning in this case, (in real project warning hided from me)
bug.c: In function ‘BUG_’:
bug.c:141:56: warning: passing argument 1 of ‘(int (*)(int))call_CALL__USING__PTR.funcint’ makes integer from pointer without a cast [-Wint-conversion]
b_1 = ((int (*)(int))call_CALL__USING__PTR.funcint) ((b_6));
^
bug.c:141:56: note: expected ‘int’ but argument is of type ‘unsigned char *’
output of the program:
Pointer value: 0x0000559e449ef090
Pointer value: 0x00000000449ef090
As you can see ADDRESS OF is treated as 32-bit integer if passed using BY VALUE, if ADDRESS OF passed without BY VALUE then everything works fine.
Best Regards,
Andrew.