GCC Newspaper
OCTOBER 6, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
cobol

cobol: Isolate source format for included files

GCC COBOL now correctly isolates source format detection for included files, preventing conflicts with the main compilation unit.

GCC’s COBOL compiler now correctly handles source file formats when files are included via the -include option. Previously, the heuristic used to determine fixed or free format for an included file could incorrectly influence the format detection for the main source file. This commit assigns separate source format state stacks to included files and the main compilation unit, ensuring format consistency.

In Details

The cdftext::lex_open function in gcc/cobol/lexio.cc previously applied source format heuristics globally. This commit modifies it to allocate a source_format_stack_t for each included file and a separate one for the main source file. This isolation prevents format detection for an included file (e.g., fixed format) from incorrectly overriding the expected format of the main compilation unit (e.g., free format), resolving issues where included files could break subsequent compilation.

For Context
COBOL
A compiled programming language designed for business applications. GCC includes a compiler for COBOL.
fixed format
A COBOL source code layout where statements must appear in specific columns, with strict rules for where code, comments, and continuation lines can be placed.
free format
A COBOL source code layout that offers more flexibility in where statements can begin and end, typically allowing code to start in any column and removing strict column restrictions.
heuristic
A practical approach or rule of thumb used by the compiler to make a decision when an exact solution is complex or impossible. In this case, it's used to guess the source code format (fixed or free).
-include option
A compiler command-line option that forces the compiler to process a specified file as if it were included at the beginning of the source code.
compilation unit
A single source file that is compiled. In C/C++, it typically includes all headers directly or indirectly included by that source file.
Filed Under: cobolcompilerlexing