Menu

Evaluate "++' in a compute expression

GnuCOBOL
13 hours ago
3 hours ago
  • Ralph Linkletter

    Ralph Linkletter - 13 hours ago

    What would be the evaluation of the "++" below
    It isn't "C" - It's COBOL
    It compiles with Micro Focus, Fujitsu, and GnuCOBOL
    The execution acts upon it as if there is only a single '+'
    I have never purposefully written such a statement

    COMPUTE IBZ-REFMOD-STRT = IBZ-REFMOD-STRT
    ++ ((IBZ-W1 - 1) * USYM-ELEM-LEN) + 1

    Compiling PLUSPLUS.COB...
    Compilation complete with no errors
    Build finished with no errors.
    Completed in 1 seconds

     

    Last edit: Ralph Linkletter 13 hours ago
  • Denis HUGONNARD-ROCHE

    Hi Ralph in fact the first + of the ++ expression is the addition operation . The second plus is interpreted as the sign of the field ie positive

    here a little program to illustrate that .

           IDENTIFICATION DIVISION.
           PROGRAM-ID . testplus .
          *>----------------------------------------------------------------
          *>
           ENVIRONMENT DIVISION.
           DATA DIVISION .
           WORKING-STORAGE  SECTION.
    
    
           01  I             PIC S9(04) BINARY .
           01  J             PIC S9(04) BINARY .
           01  K             PIC S9(04) BINARY .
           01  Z             PIC S9(04) BINARY .
    
           PROCEDURE DIVISION .
          *>
               MOVE 1 TO  I .
               MOVE 2 TO  J .
               MOVE 3 TO  K .
          *>
               COMPUTE Z = I ++J + K END-COMPUTE.
               DISPLAY 'Z = ' Z END-DISPLAY .
          *>
               COMPUTE Z = I +-J + K END-COMPUTE.
               DISPLAY 'Z = ' Z END-DISPLAY .
          *>
               MOVE -2 TO J .
          *>
               COMPUTE Z = I ++J + K END-COMPUTE.
               DISPLAY 'Z = ' Z END-DISPLAY .
          *>
               COMPUTE Z = I +-J + K END-COMPUTE.
               DISPLAY 'Z = ' Z END-DISPLAY .
          *>
          *>
               GOBACK .
    
     
    • Ralph Linkletter

      Ralph Linkletter - 3 hours ago

      Thank you Denis.
      It is obvious thanks to your example.
      It is less than obvious when the object of the second plus sign contemplates a more complex expression than a single data element.

      Thank you again !

       

Log in to post a comment.