• Re: GnuCOBOL 3.2 and CBL_OR. What am I doing wrong?

    From Arnold Trembley@arnold.trembley@att.net to comp.lang.cobol on Sat Apr 6 04:10:47 2024
    From Newsgroup: comp.lang.cobol

    On 2024-04-05 8:48 PM, Bruce Axtens wrote:
    What have I broken here? Based on code in https://gnucobol.sourceforge.io/faq/GnuCOBOLFAQ.pdf
    -a-a-a-a-a-a ...
    -a-a-a-a-a-a 01 LOGICALS.
    -a-a-a-a-a-a-a-a 03 ITEM-1 PIC 999 USAGE COMP-5.
    -a-a-a-a-a-a-a-a 03 ITEM-2 PIC 999 USAGE COMP-5.
    -a-a-a-a-a-a-a-a 03 RESULT USAGE BINARY-LONG.
    -a-a-a-a-a-a ...
    -a-a-a-a-a-a LOGICAL-OR.
    -a-a-a-a-a-a-a-a-a-a INITIALIZE RESULT.
    -a-a-a-a-a-a-a-a-a-a CALL "CBL_OR" USING ITEM-1 ITEM-2 BY VALUE 1
    -a-a-a-a-a-a-a-a-a-a-a-a-a RETURNING RESULT.
    -a-a-a-a-a-a-a-a-a-a DISPLAY ITEM-1 SPACE ITEM-2 SPACE RESULT.
    -a-a-a-a-a-a-a-a-a-a EXIT.

    ITEM-1 ITEM-2 RESULT
    00001-a 00253-a +0000000000
    00002-a 00253-a +0000000000
    00004-a 00253-a +0000000000
    00008-a 00253-a +0000000000
    00016-a 00253-a +0000000000
    00032-a 00253-a +0000000000
    00064-a 00253-a +0000000000
    00128-a 00253-a +0000000000

    Why do I only get +0?

    According to the GnuCOBOL 3.2 Programmer's Guide, the result of CBL_OR
    using ITEM-1 ITEM-2 BY VALUE 1 is the leftmost 8 bits (BY VALUE 1 BYTE)
    and is stored in ITEM-2.

    So the reason that RESULT is always zero is that it is initialized to
    zero, and it is either never changed or else CBL_OR is always successful
    and always sets the return code to zero.

    But I would wonder why ITEM-2 is always 253. How wide is a variable
    defined as PIC 999 USAGE COMP-5? According to the GnuCOBOL manual,
    COMP-5 is the native binary format for your local machine (i.e. little
    endian on x86) and the width depends on the number of digits in the
    picture clause and the "binary-size" setting in your GnuCOBOL
    configuration file.

    In the "default.conf" file the allowed binary sizes are 1-2-4-8 (or 8,
    16, 32, and 64 bits). Since values of 999 must be supported, ITEM-1 and ITEM-2 would both be 16 bits little-endian, assuming the default.conf is
    used and the instruction set is x86/AMD64.

    Kind regards,
    --
    https://www.arnoldtrembley.com/


    --
    This email has been checked for viruses by Avast antivirus software. www.avast.com
    --- Synchronet 3.21b-Linux NewsLink 1.2