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

    From Bruce Axtens@2:250/1 to All on Saturday, April 06, 2024 02:48:20
    What have I broken here? Based on code in https://gnucobol.sourceforge.io/faq/GnuCOBOLFAQ.pdf
    ...
    01 LOGICALS.
    03 ITEM-1 PIC 999 USAGE COMP-5.
    03 ITEM-2 PIC 999 USAGE COMP-5.
    03 RESULT USAGE BINARY-LONG.
    ...
    LOGICAL-OR.
    INITIALIZE RESULT.
    CALL "CBL_OR" USING ITEM-1 ITEM-2 BY VALUE 1
    RETURNING RESULT.
    DISPLAY ITEM-1 SPACE ITEM-2 SPACE RESULT.
    EXIT.

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

    Why do I only get +0?

    --- MBSE BBS v1.0.8.6 (Linux-x86_64)
    * Origin: A noiseless patient Spider (2:250/1@fidonet)
  • From Arnold Trembley@2:250/1 to All on Saturday, April 06, 2024 10:10:47
    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
           ...
           01 LOGICALS.
             03 ITEM-1 PIC 999 USAGE COMP-5.
             03 ITEM-2 PIC 999 USAGE COMP-5.
             03 RESULT USAGE BINARY-LONG.
           ...
           LOGICAL-OR.
               INITIALIZE RESULT.
               CALL "CBL_OR" USING ITEM-1 ITEM-2 BY VALUE 1
                  RETURNING RESULT.
               DISPLAY ITEM-1 SPACE ITEM-2 SPACE RESULT.
               EXIT.

    ITEM-1 ITEM-2 RESULT
    00001  00253  +0000000000
    00002  00253  +0000000000
    00004  00253  +0000000000
    00008  00253  +0000000000
    00016  00253  +0000000000
    00032  00253  +0000000000
    00064  00253  +0000000000
    00128  00253  +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

    --- MBSE BBS v1.0.8.6 (Linux-x86_64)
    * Origin: Air Applewood, The Linux Gateway to the UK & Eire (2:250/1@fidonet)