Menu

Should this compile?

Emmad
2021-11-21
2021-11-22
  • Emmad

    Emmad - 2021-11-21

    This code compiles, but I find it strange that no errors are reported.
    Pardon my lack of knowledge if this is legal anyway.
    Tested on Windows 10, GNU COBOL Version 3.2.1

    *> cobc r.cbl -free -Wall -x -o r.EXE

    *> cobc r.cbl -free -Wall -x -o r.EXE

    IDENTIFICATION DIVISION.
    PROGRAM-ID. strange.
    DATA DIVISION.
    WORKING-STORAGE SECTION.
    
    01 A PIC X.
    01   PIC X VALUE "1".  *<-- Maybe a warning is due since it is level 01 and no name is provided
    01 B.
       03 OCCURS 2.        *<-- Maybe a warning is due - No name is provided
          04 X PIC X.
    PROCEDURE DIVISION.
    
    DISPLAY 'OK'.
    STOP RUN.
    
     
    • Simon Sobisch

      Simon Sobisch - 2021-11-21

      Totally valid, likely since COBOL85 (from the VAX COBOL 74 manual it seems that this wasn't allowed).

      No name for a data item is the same as writing FILLER.

       
    • Vincent (Bryan) Coen

      Nope, totally valid the empty names are accepted as FILLER

      The 01 well clearly would be not used but the 03 occurs is fine as it
      can be accessed by the 01 or 04.

      Otherwise the compiler is not a mind reader so all is valid Cobol.

      Vince

      On 21/11/2021 21:58, Emmad wrote:

      This code compiles, but I find it strange that no errors are reported.
      Pardon my lack of knowledge if this is legal anyway.
      Tested on Windows 10, GNU COBOL Version 3.2.1

      *> cobc r.cbl -free -Wall -x -o r.EXE

      *> cobc r.cbl -free -Wall -x -o r.EXE

      IDENTIFICATION DIVISION.
      PROGRAM-ID. strange.
      DATA DIVISION.
      WORKING-STORAGE SECTION.

      01 A PIC X.
      01 PIC X VALUE "1". <-- Maybe a warning is due since it is level 01 and no name is provided
      01 B.
      03 OCCURS 2.
      <-- Maybe a warning is due - No name is provided
      04 X PIC X.
      PROCEDURE DIVISION.

      DISPLAY 'OK'.
      STOP RUN.

       
  • Emmad

    Emmad - 2021-11-21

    Great, thanks for the quick reply.

     

Anonymous
Anonymous

Add attachments
Cancel





Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.