Debian Codegraph @

gcc/cobol/gcobol.1

raw
1 .ds lang COBOL
2 .ds gcobol GCC\ \*[lang]\ Front-end
3 .ds isostd ISO/IEC 1989:2023
4 .Dd \& February 2025
5 .Dt GCOBOL 1\& "GCC \*[lang] Compiler"
6 .Os Linux
7 .Sh NAME
8 .Nm gcobol
9 .Nd \*[gcobol]
10 .Sh SYNOPSIS
11 .Nm
12 .Op Fl D Ns Ar name Ns Oo Li = Ns Ar value Oc
13 .Op Fl E
14 .Op Fl fdefaultbyte Ns Li = Ns Ar value
15 .Op Fl fsyntax-only
16 .Op Fl I Ns Ar copybook-path
17 .Op Fl fmax-errors Ns Li = Ns Ar nerror
18 .Oo
19 .Fl nomain |
20 .Fl main Ar filename |
21 .Fl main Ns Li = Ns Ar filename
22 .Fl main Ns Li = Ns Ar filename:program-id
23 .Oc
24 .Op Fl fcobol-exceptions Ar exception Ns Op Ns \/, Ns Ar exception Ns ...
25 .Op Fl copyext Ar ext
26 .Op Fl ffixed-form | Fl ffree-form
27 .Op Fl findicator-column
28 .Op Fl finternal-ebcdic
29 .Op Fl dialect Ar dialect-name
30 .Op Fl include Ar filename
31 .Op Fl preprocess Ar preprocess-filter
32 .Op Fl fflex-debug
33 .Op Fl fyacc-debug
34 .Ar filename Op ...
35 .
36 .Sh DESCRIPTION
37 .Nm
38 compiles \*[lang] source code to object code, and optionally produces an
39 executable binary or shared object. As a GCC component, it accepts
40 all options that affect code-generation and linking. Options specific
41 to \*[lang] are listed below.
42 .Bl -tag -width "\0\0debug"
43 .It Fl main Ar filename
44 .Nm
45 will generate a
46 .Fn main
47 function as an entry point calling the first PROGRAM-ID in
48 .Ar filename .
49 .Pp
50 .Fl main
51 is the default. When none of
52 .Fl nomain ,
53 .Fl c ,
54 or
55 .Fl shared ,
56 is present, an implicit
57 .Fl main
58 is inserted into the command line ahead of the first source file name.
59 .It Fl main Ns Li = Ns Ar filename
60 The .o object module for
61 .Ar filename
62 will include a
63 .Fn main
64 entry point calling the first PROGRAM-ID in
65 .Ar filename
66 .It Fl main Ns Li = Ns Ar filename:program-id
67 The .o object module for
68 .Ar filename
69 will include a
70 .Fn main
71 entry point that calls the
72 .Ar program-id
73 entry point
74 .It Fl nomain
75 No
76 .Fn main
77 entry point will be generated by this
78 compilation. The
79 .Fl nomain
80 option is incompatible with
81 .Fl main ,
82 and is implied by
83 .Fl shared .
84 It is also implied by
85 .Fl c
86 when there is no
87 .Fl main
88 present.
89 .Pp
90 See below for examples showing the use of
91 .Fl main
92 and
93 .Fl nomain.
94 .It Fl D Ar name Ns Op Li = Ns Ar expr
95 Define a CDF name (for use with
96 .Sy >>IF )
97 to have the value of
98 .Ar expr .
99 .It Fl E
100 Write the CDF-processed \*[lang] input to standard output in
101 .Em "free-form reference format".
102 Certain non-\*[lang] markers are included in the
103 output to indicate where copybook files were included. For
104 line-number consistency with the input, blank lines are retained.
105 .Pp
106 Unlike the C compiler, This option does not prevent compilation.
107 To prevent compilation, use the option
108 .D1 Fl Sy fsyntax-only
109 also.
110 .It Fl fdefaultbyte Ns Li = Ns Ar value
111 Use
112 .Ar value ,
113 a number between 0 and 255, as the default value for all
114 WORKING-STORAGE data items that have no VALUE clause. By default,
115 alphanumeric data items are initialized with blanks, and numeric data
116 items are initialized to zero. This option overrides the default with
117 .Ar value .
118 .It Fl fsyntax-only
119 Invoke only the parser. Check the code for syntax errors, but don't do
120 anything beyond that.
121 .It Fl copyext Ar ext
122 For the CDF directive
123 .D1 COPY Ar name
124 if
125 .Ar name
126 is unquoted, several varieties of
127 .Ar name
128 are tried, as described below under
129 .Xr Copybooks Ns .
130 The
131 .Fl copyext
132 option extends the names searched to include
133 .Ar ext .
134 If
135 .Ar ext
136 is all uppercase or all lowercase, both forms are tried, with preference given to the one supplied. If
137 .Ar ext
138 is mixed-case, only that version is tried.
139 For example, with
140 .D1 Fl copyext Ar .abc
141 given the CDF directive
142 .D1 COPY name
143 .Nm
144 will add to possible names searched
145 .Ql name.abc
146 and
147 .Ql name.ABC
148 in that order.
149 .It Fl ffixed-form
150 Use strict
151 .Em "fixed-form reference format"
152 in reading the \*[lang] input:
153 72-character lines, with a 6-character sequence area, and an indicator
154 column. Data past column 72 are ignored.
155 .It Fl ffree-form
156 Force the \*[lang] input to be interpreted as
157 .Em "free-form reference format".
158 Line breaks are insignificant, except that
159 .Ql *
160 at the start of a line acts as a comment marker.
161 Equivalent to
162 .Fl indicator-column Ar 0 Ns Li .
163 .
164 .It Fl findicator-column
165 describes the location of the Indicator Area in a \*[lang] file
166 in
167 .Em "Reference Format" ,
168 where the first 6 columns \(em known as the
169 .Dq "Sequence Number Area"
170 \(em are ignored, and the 7th column \(em the Indicator
171 Area \(em may hold a character of significance to the compiler.
172 .Pp
173 Although
174 .Em "reference format" ,
175 strictly speaking, ignores data after column 72,
176 with this option
177 .Nm
178 accepts long \*[lang] lines, sometimes known as
179 .Em "extended source format" .
180 Text past column 72 is treated as ordinary \*[lang] text. (Line
181 continuation remains in effect, however,
182 provided no text appears
183 .Em past
184 column 72.)
185 .Pp
186 There is no maximum line length. Regardless of source code format,
187 the entire program could appear on one line.
188 .Pp
189 By default,
190 .Nm
191 auto-detects the source code format by examining the line that
192 contains the text "program-id". When there are characters on past column 72
193 on that line, the file is assumed to be in
194 .Em "extended source format",
195 with the indicator area in column 7.
196 Otherwise, columns 1-6 are examined. If those characters are all digits
197 or blanks, the file is assumed to be in
198 .Em "fixed-form reference format",
199 also with the indicator in column 7.
200 If not auto-detected as
201 .Em "fixed-form reference format"
202 or
203 .Em "extended source format",
204 the file is assumed to be in
205 .Em "free-form reference format".
206 .Pp
207 .
208 .It Fl fcobol-exceptions Ar exception Op Ns , Ns Ar exception Ns ...
209 By default, no exception condition is enabled (including fatal ones),
210 and by the ISO standard exception conditions are enabled only via the
211 CDF
212 .Sy "TURN"
213 directive. This option enables one or more exception conditions by
214 default, as though
215 .Sy TURN
216 had appeared at the top of the first source code file.
217 This option may also appear more than once on the command line.
218 .Pp
219 The value of
220 .Ar exception
221 is a Level 1, 2, or 3 exception condition name, as described by
222 \*[isostd].
223 .Ql EC-ALL
224 means enable all exceptions.
225 .Pp
226 The
227 .Fl fno-cobol-exceptions
228 form turns off
229 .Ar exception ,
230 just as though
231 .D1 >>TURN Ar exception CHECKING OFF
232 had appeared.
233 .Pp
234 Not all exception conditions are implemented. Any that are not
235 produce a warning message.
236 .
237 .It Fl fmax-errors Ns Li = Ns Ar nerror
238 .Ar nerror
239 represents the number of error messages produced. Without this option,
240 .Nm
241 attempts to recover from a syntax error by resuming compilation at the
242 next statement, continuing until end-of-file. With it,
243 .Nm
244 counts the messages as they're produced, and stops when
245 .Ar nerror
246 is reached.
247 .It Fl fstatic-call Ns , Fl fno-static-call
248 With
249 .Fl fno-static-call ,
250 .Nm
251 never uses static linking for
252 .D1 Sy CALL Ar program
253 By default, or with
254 .Fl fstatic-call ,
255 if
256 .Ar program
257 is an alphanumeric literal,
258 .Nm
259 uses static linkage, meaning the compiler produces an external symbol
260 .Ar program
261 for the linker to resolve.
262 (In the future, that will work with
263 .Sy CONSTANT
264 data items, too.) With static linkage, if
265 .Ar program
266 is not supplied by the source code module or another object file or library
267 at build time, the linker will produce an
268 .Dq "unresolved symbol"
269 error. With
270 .Fl fno-static-call ,
271 .Nm
272 always uses dynamic linking.
273 .Pp
274 This option affects the
275 .Sy CALL
276 statement for literals only. If
277 .Ar program
278 is a non-constant data item, it is always resolved using dynamic
279 linking, with
280 .Xr dlsym 3 Ns Li ,
281 because its value is determined at run time.
282 .It Fl dialect Ar dialect-name
283 By default,
284 .Nm
285 accepts \*[lang] syntax as defined by \*[isostd], with some
286 extensions for backward compatibility with COBOL-85. To make the
287 compiler more generally useful, some additional syntax is supported by
288 this option.
289 .Pp
290 The value of
291 .Ar dialect-name
292 may be
293 .Bl -tag -compact
294 .It ibm
295 to indicate IBM COBOL 6.3 syntax, specifically
296 .D1 STOP <number>.
297 .It gnu
298 to indicate GnuCOBOL syntax
299 .It mf
300 to indicate MicroFocus syntax, specifically
301 .Sy LEVEL 78
302 constants.
303 .El
304 .Pp
305 Only a few such non-standard constructs are accepted, and
306 .Nm
307 makes no claim to emulate other compilers. But to the extent that a
308 feature is popular but nonstandard, this option provides a way to
309 support it, or add it.
310 .
311 .It Fl include Ar filename
312 Process
313 .Ar filename
314 as if
315 .D1 COPY Dq Ar filename
316 appeared as the first line of
317 the primary source file. If
318 .Ar filename
319 is not an absolute path, the directory searched is the current working
320 directory, not the directory containing the main source file. The
321 name is used verbatim. No permutations are applied, and no
322 directories searched.
323 .Pp
324 If multiple
325 .Fl include
326 options are given, the files are included in
327 the order they appear on the command line.
328 .
329 .It Fl preprocess Ar preprocess-filter
330 After all CDF text-manipulation has been applied, and before the
331 prepared \*[lang] is sent to the
332 .Sy cobol1
333 compiler, the input may be
334 further altered by one or more filters. In the tradition of
335 .Xr sed 1 ,
336 each
337 .Ar preprocess-filter
338 reads from standard input and writes to standard output.
339 .Pp
340 To supply options to
341 .Ar preprocess-filter ,
342 use a comma-separated string, similar to how linker options are supplied to
343 .Fl Sy Wl .
344 (Do not put any spaces after the commas, because the shell will treat it as an option separator.)
345 .Nm
346 replaces each comma with a space when
347 .Ar preprocess-filter
348 is invoked. For example,
349 .D1 Fl preprocess Li tee,output.cbl
350 invokes
351 .Xr tee 1
352 with the output filename argument
353 .Pa output.cbl ,
354 causing a copy of the input to be written to the file.
355 .Pp
356 .Nm
357 searches the current working directory and the PATH environment
358 variable directories for an executable file whose name matches
359 .Ar preprocess-filter .
360 The first one found is used. If none is found, an error is reported
361 and the compiler is not invoked.
362 .Pp
363 The
364 .Fl preprocess
365 option may appear more than once on the command line. Each
366 .Ar preprocess-filter
367 is applied in turn, in order of appearance.
368 .Pp
369 The
370 .Ar preprocess-filter
371 should return a zero exit status, indicating success. If it returns a
372 nonzero exit status, an error is reported and the compiler is not
373 invoked.
374 .
375 .It Fl fflex-debug Ns Li , Fl fyacc-debug
376 produce messages useful for compiler development. The
377 .Fl fflex-debug
378 option prints the tokenized input stream. The
379 .Fl fyacc-debug
380 option shows the shift and reduce actions taken by the parser.
381 .El
382 .
383 .Sh COMPILATION SCENARIOS
384 .D1 gcobol Ar xyz.cob
385 .D1 gcobol -main Ar xyz.cob
386 .D1 gcobol -main= Ns Ar xyz.cob Ar xyz.cob
387 These are equivalent. The
388 .Ar xyz.cob
389 code is compiled and a
390 .Fn main
391 function is
392 inserted that calls the first PROGRAM-ID in the
393 .Ar xyz.cob
394 source file.
395 .Pp
396 .D1 gcobol -nomain Ar xyz.cob Ar elsewhere.o
397 The
398 .Fl nomain
399 option prevents a
400 .Fn main
401 function from being generated by the gcobol compiler.
402 A
403 .Fn main
404 entry point must be present in the
405 .Ar elsewhere.o
406 module; without it the
407 linker will report a
408 .Dq "missing main"
409 error.
410 .Pp
411 .D1 gcobol Ar aaa.cob Ar bbb.cob Ar ccc.cob
412 .D1 gcobol -main Ar aaa.cob Ar bbb.cob Ar ccc.cob
413 The two commands are equivalent. The three source code modules are compiled and
414 linked together along with a generated
415 .Fn main
416 function that calls the first
417 PROGRAM-ID in the
418 .Ar aaa.cob
419 module.
420 .Pp
421 .D1 gcobol Ar aaa.cob Ar bbb.cob Fl main Ar ccc.cob
422 .D1 gcobol -main Ns = Ns Ar ccc.cob Ar aaa.cob Ar bbb.cob Ar ccc.cob
423 These two commands have the same result: An
424 .Ar a.out
425 executable is created that
426 starts executing at the first PROGRAM-ID in
427 .Ar ccc.cob .
428 .Pp
429 .D1 gcobol -main Ns = Ns Ar bbb.cob:b-entry Ar aaa.cob Ar bbb.cob Ar ccc.cob
430 An
431 .Ar a.out
432 executable is created that starts executing at the PROGRAM-ID
433 .Ar "b-entry" .
434 .Pp
435 .D1 gcobol -c Ar aaa.cob
436 .D1 gcobol -c -main Ar bbb.cob
437 .D1 gcobol -c Ar ccc.cob
438 .D1 gcobol Ar aaa.o Ar bbb.o Ar ccc.o
439 The first three commands each create a .o file. The
440 .Ar bbb.o
441 file will contain a
442 .Fn main
443 entry point that calls the first PROGRAM-ID in
444 .Ar bbb .
445 The fourth links the three .o files into an
446 .Ar a.out .
447 .
448 .Sh EBCDIC
449 The
450 .Fl finternal-ebcdic
451 option is useful when working with mainframe \*[lang] programs intended
452 for EBCDIC-encoded files. With this option, while the \*[lang] text
453 remains in ASCII, the character literals and field initial values
454 produce EBCDIC strings in the compiled binary, and any character data
455 read from a file are interpreted as EBCDIC data. The file data are
456 not
457 .Em converted ;
458 rather, the file is assumed to use EBCDIC representation. String
459 literals in the \*[lang] text
460 .Em are
461 converted, so that they can be compared meaningfully with data in the file.
462 .Pp
463 Only file data and character literals are affected. Data read from
464 and written to the environment, or taken from the command line, are
465 interpreted according the
466 .Xr locale 7
467 in force during execution. The same is true of
468 .Sy ACCEPT
469 and
470 .Sy DISPLAY .
471 Names known to the operating system, such as file names and the names
472 of environment variables, are processed verbatim.
473 .Pp
474 At the present time, this is an all-or-nothing setting. Support for
475 .Sy USAGE
476 and
477 .Sy CODESET ,
478 which would allow conversion between encodings, remains a future goal.
479 .Pp
480 See also
481 .Sx "Feature-set Variables" ,
482 below.
483 .
484 .Sh REDEFINES ... USAGE POINTER
485 Per ISO, an item that
486 .Sy REDEFINES
487 another may not be larger than the item it redefines, unless that item
488 has LEVEL 01 and is not EXTERNAL. In
489 .Nm ,
490 using
491 .Fl dialect Ar ibm ,
492 this rule is relaxed for
493 .Sy REDEFINES
494 with
495 .Sy USAGE POINTER
496 whose redefined member is a 4-byte
497 .Sy USAGE COMP-5
498 (usually
499 .Sy PIC S9(8) Ns ),
500 or vice-versa.
501 In that case, the redefined member is re-sized to be 8 bytes, to
502 accommodate the pointer. This feature allows pointer arithmetic on a
503 64-bit system with source code targeted at a 32-bit system.
504 .Pp
505 See also
506 .Sx "Feature-set Variables" ,
507 below.
508 .
509 .Sh IMPLEMENTATION NOTES
510 .Nm
511 is a gcc compiler, and follows gcc conventions where applicable.
512 Sometimes those conventions (and user expectations) conflict with
513 common Mainframe practice. Unless required of the compiler by the ISO
514 specification, any such conflicts are resolved in favor of gcc.
515 .Ss Linking
516 Unlike, C, the \*[lang]
517 .Sy CALL
518 statement implies dynamic linking, because for
519 .D1 Sy CALL Ar program
520 .Ar program
521 can be a variable whose value is determined at runtime.
522 However, the parameter may also be compile-time constant, either an
523 alphanumeric literal, or a
524 .Sy CONSTANT
525 data item.
526 .Pp
527 .Nm
528 supports static linking where possible, unless defeated by
529 .Fl fno-static-call .
530 If the parameter value is known at compile time, the compiler produces
531 an external reference to be resolved by the linker. The referenced
532 program is normally supplied via an object module, a static library,
533 or a shared object. If it is not supplied, the linker will report an
534 .Dq "unresolved symbol"
535 error, either at build time or, if using a shared object, when the
536 program is executed. This feature informs the programmer of the error
537 at the earliest opportunity.
538 .Pp
539 Programs that are expected to execute
540 correctly in the presence of an unresolved symbol (perhaps because the
541 program logic won't require that particular
542 .Sy CALL )
543 can use the
544 .Fl no-static-call
545 option. That forces all
546 .Sy CALL
547 statements to be resolved dynamically, at runtime.
548 .ig
549 Programs that are expected to execute
550 correctly in the presence of an unresolved symbol (perhaps because the
551 program logic won't require that particular
552 .Sy CALL )
553 can use linker options to produce an executable anyway.
554 .Pp
555 One corner case yet remains. The
556 .Sy CALL
557 statement includes an
558 .Sy "ON ERROR"
559 clause whose purpose is to handle errors arising when the called program is not found.
560 Control is transferred to the
561 .Sy "ON ERROR"
562 clause when the
563 .Sy EC-PROGRAM-NOT-FOUND
564 exception condition is raised. That exception condition is not raised in
565 .Nm
566 when:
567 .Bl -bullet -compact
568 .It
569 the
570 .Sy CALL
571 parameter
572 is known at compile time, i.e., is an alphanumeric literal or
573 .Sy CONSTANT
574 data item, and
575 .It
576 the executable was generated with the linker option to ignore unresolved symbols.
577 .El
578 In that case, the program is terminated with a signal. No recovery with
579 .Sy "ON ERROR"
580 is possible.
581 .Pp
582 Should your program meet those particular conditions, all is not lost.
583 There are workarounds, and an option could be added to use dynamic
584 linking for all
585 .Sy CALL
586 statement, regardless of compile-time constants.
587 ..
588 .
589 .Ss Implemented Exception Conditions
590 By default, per ISO, no EC is enabled. Implemented ECs may be enabled
591 on the command line or via the
592 .Sy TURN
593 directive. Any attempt to enable an EC that is not implemented is
594 treated as an error.
595 .Pp
596 An enabled EC not handled by a
597 .Sy DECLARATIVE
598 is written to the system log and to standard error. (The authors
599 intend to make that an option.) A fatal EC not handled with
600 .Sy RESUME
601 ends with a call to
602 .Xr abort 3
603 and process termination.
604 .Pp
605 Not all Exception Conditions are implemented. Any attempt to enable
606 an EC that that is not implemented produces a warning message.
607 The following are implemented:
608 .Pp
609 .Bl -tag -offset 5n -compact
610 .It EC-FUNCTION-ARGUMENT
611 for the following functions:
612 .Bl -item -compact
613 .It
614 ACOS
615 .It
616 ANNUITY
617 .It
618 ASIN
619 .It
620 LOG
621 .It
622 LOG10
623 .It
624 PRESENT-VALUE
625 .It
626 SQRT
627 .El
628 .It EC-SORT-MERGE-FILE-OPEN
629 .It EC-BOUND-SUBSCRIPT
630 subscript not an integer, less than 1, or greater than occurs
631 .It EC-BOUND-REF-MOD
632 refmod start not an integer, start less than 1, start greater than
633 variable size, length not an integer, length less than 1, and
634 start+length exceeds variable size
635 .It EC-BOUND-ODO
636 DEPENDING not an integer, greater than occurs upper limit,
637 less than occurs lower limit, and subscript greater than DEPENDING for sending item
638 .It EC-SIZE-ZERO-DIVIDE
639 for both fixed-point and floating-point division
640 .It EC-SIZE-TRUNCATION
641 .It EC-SIZE-EXPONENTIATION
642 .El
643 .Pp
644 As of this writing, no \*[lang] compiler documents a complete
645 implementation of \*[isostd] Exception Conditions.
646 .Nm
647 will give priority to those ECs that the user community deems most
648 valuable.
649 .
650 .Sh EXTENSIONS TO ISO \*[lang]
651 Standard \*[lang] has no provision for environment variables as defined
652 by Unix and Windows, or command-line arguments.
653 .Nm
654 supports them using syntax similar to that of GnuCOBOL. ISO and IBM
655 also define incompatible ways to return the program's exit status to
656 the operating system.
657 .Nm
658 supports IBM syntax.
659 .
660 .Ss Environment Variables
661 To read an environment variable:
662 .Pp
663 .D1 ACCEPT Ar target Li FROM ENVIRONMENT Ar envar
664 .Pp
665 where
666 .Ar target
667 is a data item defined in
668 .Sy "DATA DIVISION" ,
669 and
670 .Ar envar
671 names an environment variable.
672 .Ar envar
673 may be a string literal or alphanumeric data item whose value is the
674 name of an environment variable. The value of the named environment
675 variable is moved to
676 .Ar target .
677 The rules are the same as for
678 .Sy MOVE .
679 .Pp
680 To write an environment variable:
681 .Pp
682 .D1 SET ENVIRONMENT Ar envar Li TO Ar source
683 .Pp
684 where
685 .Ar source
686 is a data item defined in
687 .Sy DATA DIVISION ,
688 and
689 .Ar envar
690 names an environment variable.
691 .Ar envar
692 again may be a string literal or alphanumeric data item whose value is the
693 name of an environment variable. The value of the named environment
694 variable is set to the value of
695 .Ar source .
696 .
697 .Ss Command-line Arguments
698 To read command-line arguments, use the registers
699 .Sy COMMAND-LINE
700 and
701 .Sy COMMAND-LINE-COUNT
702 in an
703 .Sy ACCEPT
704 statement (only).
705 Used without a subscript,
706 .Sy COMMAND-LINE
707 returns the whole command line as a single string. With a subscript,
708 .Sy COMMAND-LINE
709 is a table of command-line arguments. For example, if the
710 program is invoked as
711 .sp
712 .D1 Sy ./program Fl i Ar input Ar output
713 .sp
714 then
715 .sp
716 .D1 ACCEPT target FROM COMMAND-LINE(3)
717 .sp
718 moves
719 .Ar input
720 into
721 .Ar target .
722 The program name is the first thing in the whole command line and is
723 found in COMMAND-LINE(1)
724 .Sy COMMAND-LINE
725 table.
726 .Pp
727 To discover how many arguments were provided on the command line, use
728 .sp
729 .D1 ACCEPT Ar target Li FROM COMMAND-LINE-COUNT
730 .sp
731 If
732 .Sy ACCEPT
733 refers to a nonexistent environment variable or command-line
734 argument, the target is set to
735 .Sy LOW-VALUES .
736 .Pp
737 The system command line parameters can also be accessed through the LINKAGE
738 SECTION in the program where execution starts. The data structure looks like
739 this:
740 .Bd -literal
741 linkage section.
742 01 argc pic 999.
743 01 argv.
744 02 argv-table occurs 1 to 100 times depending on argc.
745 03 argv-element pointer.
746 01 argv-string pic x(100) .
747 .Ed
748 and the code to access the third parameter looks like this
749 .Bd -literal
750 procedure division using by value argc by reference argv.
751 set address of argv-string to argv-element(3)
752 display argv-string
753 .Ed
754 .
755 .Ss #line directive
756 The parser accepts lines in the form
757 .D1 #line Ar lineno Dq Ar filename Ns .
758 The effect is to set the current line number to
759 .Ar lineno
760 and the current input filename to
761 .Ar filename .
762 Preprocessors may use this directive to control the filename and line
763 numbers reported in error messages and in the debugger.
764 .
765 .Ss SELECT ... ASSIGN TO
766 In the phrase
767 .sp
768 .D1 ASSIGN TO Ar filename
769 .sp
770 .Ar filename
771 may appear in quotes or not. If quoted, it represents a filename as
772 known to the operating system. If unquoted, it names either a data
773 element or an environment variable containing the name of a file.
774 If
775 .Ar filename
776 matches the name of a data element, that element is used. If not,
777 resolution of
778 .Ar filename
779 is deferred until runtime, when the name must appear in the program's
780 environment.
781 .
782 .Sh ISO \*[lang] Implementation Status
783 .Ss USAGE Data Types
784 .Nm
785 supports the following
786 .Sy USAGE IS
787 clauses:
788 .Bl -tag -compact -width POINTER\0
789 .It Sy INDEX
790 for use as an index in a table.
791 .It Sy POINTER
792 for variables whose value is the address of an external function,
793 .Sy PROGRAM-ID ,
794 or data item. Assignment is via the
795 .Sy SET
796 statement.
797 .It Sy BINARY, Sy COMP , Sy COMPUTATIONAL, Sy COMP-4, Sy COMPUTATIONAL-4
798 big-endian integer, 1 to 16 bytes, per PICTURE.
799 .It Sy COMP-1 , Sy COMPUTATIONAL-1 , Sy FLOAT-BINARY-32
800 IEEE 754 single-precision (4-byte) floating point, as provided by the
801 hardware.
802 .It Sy COMP-2 , Sy COMPUTATIONAL-2 , Sy FLOAT-BINARY-64
803 IEEE 754 double-precision (8-byte) floating point, as provided by the
804 hardware.
805 .It Sy COMP-3 , Sy COMPUTATIONAL-3, Sy PACKED-DECIMAL
806 currently unimplemented.
807 .It Sy COMP-5 , Sy COMPUTATIONAL-5
808 little-endian integer, 1 to 16 bytes, per
809 .Sy PICTURE.
810 .It Sy FLOAT-BINARY-128 , FLOAT-EXTENDED
811 implements 128-bit floating point, per IEEE 754.
812 .El
813 .Pp
814 .Nm
815 supports ISO integer
816 .Sy BINARY-<type>
817 types, most of which alias
818 .Sy COMP-5.
819 .
820 .hw unsigned
821 .sp
822 .TS
823 LB LB LB LB
824 LB LB LB LB
825 L L L L .
826 COMP-5 Compatible
827 Picture BINARY Type Bytes Value
828 T{
829 BINARY-CHAR [UNSIGNED]
830 T} 1 0 \(em 256
831 S9(1...4) T{
832 BINARY-CHAR SIGNED
833 T} 1 -128 \(em +127
834 \09(1...4) T{
835 BINARY-SHORT [UNSIGNED]
836 T} 2 0 \(em 65535
837 S9(1...4) T{
838 BINARY-SHORT SIGNED
839 T} 2 -32768 \(em +32767
840 \09(5...9) T{
841 BINARY-LONG [UNSIGNED]
842 T} 4 0 \(em 4,294,967,295
843 S9(5...9) T{
844 BINARY-LONG SIGNED
845 T} 4 T{
846 -2,147,483,648 \(em +2,147,483,647
847 T}
848 \09(10...18) T{
849 BINARY-LONG-LONG [UNSIGNED]
850 T} 8 T{
851 0 \(em 18,446,744,073,709,551,615
852 T}
853 S9(10...18) T{
854 BINARY-LONG-LONG SIGNED
855 T} 8 T{
856 -9,223,372,036,854,775,808 \(em +9,223,372,036,854,775,807
857 T}
858 .TE
859 .Pp
860 These define a size (in bytes) and cannot be
861 used with a
862 .Sy PICTURE
863 clause.
864 Per the ISO standard,
865 .Sy SIGNED
866 is the default for the
867 .Sy "BINARY-" Ns Ar type
868 aliases.
869 .Pp
870 All computation \(em both integer and floating point \(em is done
871 using 128-bit intermediate forms.
872 .
873 .Ss Environment Names
874 In
875 .Nm
876 .sp
877 .Dl DISPLAY UPON
878 .sp
879 maps
880 .Sy SYSOUT
881 and
882 .Sy STDOUT
883 to standard output, and
884 .Sy SYSPUNCH ,
885 .Sy SYSPCH
886 and
887 .Sy STDERR
888 to standard error.
889 .
890 .Ss Exit Status
891 .Nm
892 supports the ISO syntax for returning an exit status to the operating system,
893 .Pp
894 .D1 STOP RUN Oo WITH Oc Bro NORMAL | ERROR Brc Oo STATUS Oc Ar status
895 .Pp
896 In addition,
897 .Nm
898 also supports the IBM syntax for returning an exit status to
899 the operating system. Use the
900 .Sy RETURN-CODE
901 register:
902 .Bd -literal -offset indent
903 MOVE ZERO TO RETURN-CODE.
904 GOBACK.
905 .Ed
906 .Pp
907 The
908 .Sy RETURN-CODE
909 register is defined as a 4-byte binary integer.
910 .ig
911 .Pp
912 The ISO standard supports an extended form of
913 .Sy GOBACK :
914 .Pp
915 .D1 GOBACK {ERROR | NORMAL} WITH Ar status
916 .Pp
917 where
918 .Ar status
919 is a numeric data item or literal. This syntax has the same effect as:
920 .Bd -literal -offset indent
921 MOVE status TO RETURN-CODE.
922 GOBACK.
923 .Ed
924 The use of
925 .Sy ERROR
926 or
927 .Sy NORMAL
928 has no effect; the two are interchangeable.
929 ..
930 .
931 .Sh COMPILER-DIRECTING FACILITY
932 The CDF should be used with caution because no comprehensive test
933 suite has been identified.
934 .
935 .Ss CDF Text Manipulation
936 .Bl -tag -width >>DEFINE
937 .It Sy COPY Ar copybook Li Oo OF|BY Ar library Oc Oo Sy REPLACING ... Oc
938 If
939 .Ar copybook
940 is a literal, it treated a literal filename, which either does or does not exist. If
941 .Ar copybook
942 is a \*[lang] word,
943 .Nm
944 looks first for an environment variable named
945 .Va copybook
946 and, if found, uses the contents of that variable as the name of the
947 copybook file. If that file does not exist, it continues looking for
948 a file named one of:
949 .sp
950 .Bl -bullet -compact -offset 5n
951 .It
952 .Pa copybook
953 (literally)
954 .It
955 .Pa copybook.cpy
956 .It
957 .Pa copybook.CPY
958 .It
959 .Pa copybook.cbl
960 .It
961 .Pa copybook.CBL
962 .It
963 .Pa copybook.cob
964 .It
965 .Pa copybook.COB
966 .El
967 .sp
968 in that order. It looks first in the same directory as the source
969 code file, and then in any
970 .Ar copybook-path
971 named with the
972 .Fl I
973 option.
974 .
975 .\" FIXME: need escape mechanism for directories with ':' in the name.
976 .Ar copybook-path
977 may (like the shell's
978 .Ev PATH
979 variable) be a colon-separated list.
980 The
981 .Fl I
982 option may occur multiple times on the command line. Each successive
983 .Ar copybook-path
984 is concatenated to previous ones.
985 Relative paths (having no leading
986 .Ql / Ns
987 \&)
988 are searched relative to the compiler's current working directory.
989 .Pp
990 For example,
991 .D1 \&
992 .D1 Fl I Li /usr/local/include:include
993 .D1 \&
994 searches first the directory where the \*[lang] program is found, next in
995 .Pa /usr/local/include ,
996 and finally in an
997 .Pa include
998 subdirectory of the directory from which
999 .Nm
1000 was invoked.
1001 .Pp
1002 For the
1003 .Sy REPLACING
1004 phrase, both the modern pseudo-text and the \*[lang]/85 forms are
1005 recognized. (The older forms are used in the NIST CCVS/85 test suite.)
1006 .It Sy REPLACE ...
1007 .Nm
1008 supports the full ISO
1009 .Sy REPLACE
1010 syntax.
1011 .El
1012 .
1013 .Ss CDF Directives
1014 .\"Bl -tag -width >>PROPAGATE
1015 .Bl -tag -width >>DEFINE
1016 .It >> Ns Sy DEFINE Ar name Sy AS Bro Ar expression Li | Sy PARAMETER Brc Op Sy OVERRIDE
1017 Define
1018 .Ar name
1019 as a compilation variable to have the value
1020 .Ar expression .
1021 If
1022 .Ar name
1023 was previously defined,
1024 .Sy OVERRIDE
1025 is required, else the directive is invalid.
1026 .Sy AS PARAMETER
1027 is accepted, but has no effect in
1028 .Nm .
1029 .
1030 .It >> Ns Sy DEFINE Ar name AS Sy OFF
1031 releases the definition
1032 .Ar name ,
1033 making it subsequently invalid for use.
1034 .\" ISO requires AS; cdf.y does not.
1035 .
1036 .It >> Ns Sy IF Ar cce Ar text Oo >> Ns Sy ELSE Ar alt-text Oc Li >> Ns Sy END-IF
1037 evaluates
1038 .Ar cce ,
1039 a
1040 .Em "constant conditional expression\/" ,
1041 for conditional compilation.
1042 If a name,
1043 .Ar cce
1044 may be defined with the
1045 .Fl D
1046 command-line parameter. If true, the \*[lang] text
1047 .Ar text
1048 is compiled. If false,
1049 .Ar else-text ,
1050 if present, is compiled.
1051 .Bo Sy IS Bo Sy NOT Bc Bc Sy DEFINED
1052 is supported. Boolean literals are not supported.
1053 .
1054 .It >> Ns Sy EVALUATE
1055 Not implemented.
1056 .It >> Ns Sy CALL-CONVENTION Ar convention
1057 .Ar convention
1058 may be one of:
1059 .Bl -tag -compact
1060 .It Sy \*[lang]
1061 Use standard \*[lang] case-insensitive symbol-name matching. For
1062 .Sy CALL Dq Ar name ,
1063 .Ar name
1064 is rendered by the compiler in lowercase.
1065 .It Sy C
1066 Use case-sensitive symbol-name matching. The
1067 .Sy CALL
1068 target is not changed in any way; it is used verbatim.
1069 .It Sy VERBATIM
1070 An alias for >>\c
1071 .Sy "CALL-CONVENTION C" .
1072 .El
1073 .It >> Ns Sy COBOL-WORDS EQUATE Ar keyword Sy WITH Ar alias
1074 makes
1075 .Ar alias
1076 a synonym for
1077 .Ar keyword .
1078 .It >> Ns Sy COBOL-WORDS UNDEFINE Ar keyword
1079 .Ar keyword
1080 is removed from the \*[lang] grammar. Use of it in a program will provoke
1081 a syntax error from the compiler.
1082 .It >> Ns Sy COBOL-WORDS SUBSTITUTE Ar keyword Sy BY Ar new-word
1083 .Ar keyword
1084 is deleted as a keyword from the grammar, replaced by
1085 .Ar new-word .
1086 .Ar keyword
1087 may thereafter be used as a user-defined word.
1088 .It >> Ns Sy COBOL-WORDS RESERVE Ar new-word
1089 Treat
1090 .Ar new-word
1091 as a \*[lang] keyword. It cannot be used by the program, either as a
1092 keyword or as a user-defined word.
1093 .
1094 .It >> Ns Sy DISPLAY Ar string ...
1095 Write
1096 .Ar string
1097 to standard error as a warning message.
1098 .It >> Ns Sy SOURCE Ar format
1099 .Ar format
1100 may be one of:
1101 .Bl -tag -compact
1102 .It Sy FIXED
1103 Source conforms to \*[lang]
1104 .Em "fixed-form reference format"
1105 with unlimited line length.
1106 .It Sy FREE
1107 Source conforms to \*[lang]
1108 .Em "free-form reference format".
1109 .Ql "*"
1110 at the beginning of a line is recognized as a comment.
1111 .El
1112 .El
1113 .Pp
1114 .Bl -tag -width >>PROPAGATE -compact
1115 .It >> Ns Sy FLAG-02
1116 Not implemented.
1117 .It >> Ns Sy FLAG-85
1118 Not implemented.
1119 .It >> Ns Sy FLAG-NATIVE-ARITHMETIC
1120 Not implemented.
1121 .It >> Ns Sy LEAP-SECOND
1122 Not implemented.
1123 .It >> Ns Sy LISTING
1124 Not implemented.
1125 .It >> Ns Sy PAGE
1126 Not implemented.
1127 .It >> Ns Sy PROPAGATE
1128 Not implemented.
1129 .It >> Ns Sy PUSH Ar directive
1130 .It >> Ns Sy POP Ar directive
1131 With
1132 .Sy PUSH ,
1133 push CDF state onto a stack.
1134 With
1135 .Sy POP ,
1136 return to the prior pushed state.
1137 .Ar directive
1138 may be one of
1139 .Bl -tag -compact
1140 .It Sy CALL-CONVENTION
1141 .It Sy COBOL-WORDS
1142 .It Sy DEFINE
1143 .It Sy SOURCE FORMAT
1144 .It Sy TURN
1145 .El
1146 .
1147 .It >> Ns Sy TURN Oo
1148 .Ar ec Oo Ar file Li ... Oc ...
1149 .Oc Sy CHECKING Bro Oo Sy ON Oc Oo Oo Sy WITH Oc Sy LOCATION Oc | Sy OFF Brc
1150 Enable (or, with
1151 .Sy OFF ,
1152 disable) exception condition
1153 .Ar ec
1154 optionally associated with the file connectors
1155 .Ar file .
1156 If
1157 .Sy LOCATION
1158 is specified,
1159 .Nm
1160 reports at runtime the source filename and line number of the
1161 statement that triggered the exception condition.
1162 .El
1163 .
1164 .Ss Feature-set Variables
1165 Some command-line options affect CDF
1166 .Em "feature-set"
1167 variables that are special to
1168 .Nm .
1169 They can be set and tested using
1170 .Sy >>DEFINE
1171 and
1172 .Sy >>IF ,
1173 and are distinguished by a leading
1174 .Ql \&%
1175 in the name, which is otherwise invalid in a \*[lang] identifier:
1176 .Pp
1177 .Bl -tag -compact
1178 .It Sy %EBCDIC-MODE
1179 is set by
1180 .Fl finternal-ebcdic .
1181 .It Sy %64-BIT-POINTER
1182 is implied by
1183 .Fl "dialect ibm" .
1184 .El
1185 .Pp
1186 To set a feature-set variable, use
1187 .Dl >>SET Ar feature Li [AS] {ON | OFF}
1188 If
1189 .Ar feature
1190 is
1191 .Sy %EBCDIC-MODE ,
1192 the directive must appear before
1193 .Sy PROGRAM-ID .
1194 .Pp
1195 To test a feature-set variable, use
1196 .Dl >>IF Ar feature Li DEFINED
1197 .
1198 .Ss Intrinsic functions
1199 .Nm
1200 implements all intrinsic functions defined by \*[isostd], plus a few
1201 others. They are listed alphabetically below.
1202 .Bl -item -compact
1203 .It
1204 ABS ACOS ANNUITY ASIN ATAN
1205 .It
1206 BASECONVERT BIT-OF BIT-TO-CHAR BOOLEAN-OF-INTEGER BYTE-LENGTH
1207 .It
1208 CHAR CHAR-NATIONAL COMBINED-DATETIME CONCAT CONVERT COS CURRENT-DATE
1209 .It
1210 DATE-OF-INTEGER DATE-TO-YYYYMMDD DAY-OF-INTEGER DAY-TO-YYYYDDD DISPLAY-OF
1211 .It
1212 E EXCEPTION-FILE
1213 EXCEPTION-FILE-N EXCEPTION-LOCATION EXCEPTION-LOCATION-N
1214 EXCEPTION-STATEMENT EXCEPTION-STATUS EXP EXP10
1215 .It
1216 FACTORIAL FIND-STRING
1217 FORMATTED-CURRENT-DATE FORMATTED-DATE FORMATTED-DATETIME
1218 FORMATTED-TIME FRACTION-PART
1219 .It
1220 HEX-OF HEX-TO-CHAR HIGHEST-ALGEBRAIC
1221 .It
1222 INTEGER INTEGER-OF-BOOLEAN INTEGER-OF-DATE INTEGER-OF-DAY
1223 INTEGER-OF-FORMATTED-DATE INTEGER-PART
1224 .It
1225 LENGTH LOCALE-COMPARE
1226 LOCALE-DATE LOCALE-TIME LOCALE-TIME-FROM-SECONDS LOG LOG10 LOWER-CASE
1227 LOWEST-ALGEBRAIC
1228 .It
1229 MAX MEAN MEDIAN MIDRANGE MIN MOD MODULE-NAME
1230 .It
1231 NATIONAL-OF NUMVAL NUMVAL-C NUMVAL-F ORD
1232 .It
1233 ORD-MAX ORD-MIN
1234 .It
1235 PI PRESENT-VALUE
1236 .It
1237 RANDOM RANGE REM REVERSE
1238 .It
1239 SECONDS-FROM-FORMATTED-TIME
1240 SECONDS-PAST-MIDNIGHT SIGN SIN SMALLEST-ALGEBRAIC SQRT
1241 STANDARD-COMPARE STANDARD-DEVIATION SUBSTITUTE SUM
1242 .It
1243 TAN TEST-DATE-YYYYMMDD TEST-DAY-YYYYDDD TEST-FORMATTED-DATETIME
1244 TEST-NUMVAL TEST-NUMVAL-C TEST-NUMVAL-F TRIM
1245 .It
1246 ULENGTH UPOS UPPER-CASE
1247 USUBSTR USUPPLEMENTARY UUID4 UVALID UWIDTH
1248 .It
1249 VARIANCE
1250 .It
1251 WHEN-COMPILED
1252 .It
1253 YEAR-TO-YYYY
1254 .El
1255 .
1256 .Ss Binary floating point DISPLAY
1257 How the DISPLAY presents binary floating point numbers depends on the value.
1258 .Pp
1259 When a value has six or fewer decimal digits to the left of the
1260 decimal point, it is expressed as
1261 .Em 123456.789... .
1262 .Pp
1263 When a value is less than 1 and has no more than three zeroes to the
1264 right of the decimal point, it is expressed as
1265 .Em 0.0001234... .
1266 .Pp
1267 Otherwise, exponential notation is used:
1268 .Em 1.23456E+7 .
1269 .Pp
1270 In all cases, trailing zeroes on the right of the number are removed
1271 from the displayed value.
1272 .Pp
1273 .Bl -tag -compact -width FLOAT-EXTENDED
1274 .It COMP-1
1275 displayed with 9 decimal digits.
1276 .It COMP-2
1277 displayed with 17 decimal digits.
1278 .It FLOAT-EXTENDED
1279 displayed with 36 decimal digits.
1280 .El
1281 .Pp
1282 Those digit counts are consistent with the IEEE 754 requirements for
1283 information interchange. As one example, the description for COMP-2
1284 binary64 values (per Wikipedia).
1285 .Pp
1286 If an IEEE 754 double-precision number is converted to a decimal
1287 string with at least 17 significant digits, and then converted back to
1288 double-precision representation, the final result must match the
1289 original number.
1290 .Pp
1291 17 digits was chosen so that the
1292 .Sy DISPLAY
1293 statement shows the contents
1294 of a COMP-2 variable without hiding any information.
1295 .
1296 .Ss Binary floating point MOVE
1297 During a
1298 .Sy MOVE
1299 statement, a floating-point value may be truncated. It will not be
1300 unusual for Numeric Display values to be altered when moved through a
1301 floating-point value.
1302 .Pp
1303 This program:
1304 .Bd -literal
1305 01 PICV999 PIC 9999V999.
1306 01 COMP2 COMP-2.
1307 PROCEDURE DIVISION.
1308 MOVE 1.001 to PICV999
1309 MOVE PICV999 TO COMP2
1310 DISPLAY "The result of MOVE " PICV999 " TO COMP2 is " COMP2
1311 MOVE COMP2 to PICV999
1312 DISPLAY "The result of MOVE COMP2 TO PICV999 is " PICV999
1313 .Ed
1314 .Pp
1315 generates this result:
1316 .Bd -literal
1317 The result of MOVE 0001.001 TO COMP2 is 1.00099999999999989
1318 The result of MOVE COMP2 TO PICV999 is 0001.000
1319 .Ed
1320 .Pp
1321 However, the internal implementation can produce results that might be seem surprising:
1322 .Bd -literal
1323 The result of MOVE 0055.110 TO COMP2 is 55.1099999999999994
1324 The result of MOVE COMP2 TO PICV999 is 0055.110
1325 .Ed
1326 .Pp
1327 The source of this inconsistency is the way
1328 .Nm
1329 stores and converts
1330 numbers. Converting the floating-point value to the numeric display
1331 value 0055110 is done by multiplying 55.109999...\& by 1,000 and then
1332 truncating the result to an integer. And it turns out that even
1333 though 55.11 can't be represented in floating-point as an exact value,
1334 the product of the multiplication, 55110, is an exact value.
1335 .Pp
1336 In cases where it is important for conversions to have predictable
1337 results, we need to be able to apply rounding, which can be done with
1338 an arithmetic statement:
1339 .Bd -literal
1340 MOVE 1.001 to PICV999
1341 MOVE PICV999 TO COMP2
1342 DISPLAY "The result of MOVE " PICV999 " TO COMP2 is " COMP2
1343 MOVE COMP2 to PICV999
1344 DISPLAY "The result of MOVE COMP2 TO PICV999 is " PICV999
1345 ADD COMP2 to ZERO GIVING PICV999 ROUNDED
1346 DISPLAY "The result of ADD COMP2 to ZERO GIVING PICV999 ROUNDED is " PICV999
1347 .sp
1348 The result of MOVE 0001.001 TO COMP2 is 1.00099999999999989
1349 The result of MOVE COMP2 TO PICV999 is 0001.000
1350 The result of ADD COMP2 to ZERO GIVING PICV999 ROUNDED is 0001.001
1351 .Ed
1352 .Ss Binary floating point computation
1353 .Nm
1354 attempts to do internal computations using binary integers when
1355 possible. Thus, simple arithmetic between binary values and numeric
1356 display values conclude with binary intermediate results.
1357 .Pp
1358 If a floating-point value gets included in the mix of variables
1359 specified for a calculation, then the intermediate result becomes a
1360 128-bit floating-point value.
1361 .
1362 .Ss A warning about binary floating point comparison
1363 The cardinal rule when doing comparisons involving floating-point
1364 values: Never, ever, test for equality. It's just not worth the hassle.
1365 .Pp
1366 For example:
1367 .Bd -literal
1368 WORKING-STORAGE SECTION.
1369 01 COMP1 COMP-1 VALUE 555.11.
1370 01 COMP2 COMP-2 VALUE 555.11.
1371 PROCEDURE DIVISION.
1372 DISPLAY "COMPARE " COMP1 " with " COMP2
1373 IF COMP1 EQUAL COMP2 DISPLAY "Equal" ELSE DISPLAY "Not equal" END-IF
1374 .sp
1375 MOVE COMP1 to COMP2
1376 DISPLAY "COMPARE " COMP1 " with " COMP2
1377 IF COMP1 EQUAL COMP2 DISPLAY "Equal" ELSE DISPLAY "Not equal" END-IF
1378 .Ed
1379 .Pp
1380 the results:
1381 .Bd -literal
1382 COMPARE 555.1099854 with 555.110000000000014
1383 Not equal
1384 COMPARE 555.1099854 with 555.1099853515625
1385 Equal
1386 .Ed
1387 .Pp
1388 Why? Again, it has to do with the internals of
1389 .Nm .
1390 When differently sized floating-point values need to be compared, they
1391 are first converted to 128-bit floats. And it turns out that when a
1392 COMP1 is moved to a COMP2, and they are both converted to
1393 FLOAT-EXTENDED, the two resulting values are (probably) equal.
1394 .Pp
1395 Avoid testing for equality unless you really know what you are doing
1396 and you really test the code. And then avoid it anyway.
1397 .Pp
1398 Finally, it is observably the case that the
1399 .Nm
1400 implementations of floating-point conversions and comparisons don't
1401 precisely match the behavior of other \*[lang] compilers.
1402 .Pp
1403 You have been warned.
1404 .
1405 .Sh ENVIRONMENT
1406 .Bl -tag -width COBPATH
1407 .It Ev COBPATH
1408 If defined, specifies the directory paths to be used by the
1409 .Nm
1410 runtime library,
1411 .Pa libgcobol.so ,
1412 to locate shared objects.
1413 Like
1414 .Ev LD_LIBRARY_PATH ,
1415 it may contain several directory names separated by a colon
1416 .Pq Ql \&: .
1417 .Ev COBPATH
1418 is searched first, followed by
1419 .Ev LD_LIBRARY_PATH .
1420 .Pp
1421 Each directory is searched for files whose name ends in
1422 .Ql ".so" .
1423 For each such file,
1424 .Xr dlopen 3
1425 is attempted, and, if successful
1426 .Xr dlsym 3 .
1427 No relationship is defined between the symbol's name and the filename.
1428 .Pp
1429 Without
1430 .Ev COBPATH ,
1431 binaries produced by
1432 .Nm
1433 behave as one might expect of any program compiled with gcc. Any
1434 shared objects needed by the program are mentioned on the command line
1435 with a
1436 .Fl l Ns Ar library
1437 option, and are found by following the executable's
1438 .Pa RPATH
1439 or otherwise per the configuration of the runtime linker,
1440 .Xr ld.so 8 .
1441 .
1442 .It Ev UPSI
1443 \*[lang] defines a User Programmable Status Indicator (UPSI) switch. In
1444 .Nm ,
1445 the settings are denoted
1446 .Sy UPSI-0
1447 through
1448 .Sy UPSI-7 ,
1449 where 0-7 indicates a bit position. The value of the UPSI switches is
1450 taken from the
1451 .Ev UPSI
1452 environment variable, whose value is a string of up to eight 1's and
1453 0's. The first character represents the value of
1454 .Sy UPSI-0 ,
1455 and missing values are assigned 0. For example,
1456 .Sy UPSI=1000011
1457 in the environment sets bits 0, 5, and 6 on, which means that
1458 .Sy UPSI-0 ,
1459 .Sy UPSI-5 ,
1460 and
1461 .Sy UPSI-6
1462 are on.
1463 .It Ev GCOBOL_TEMPDIR
1464 causes any temporary files created during CDF processing to be written
1465 to a file whose name is specified in the value of
1466 .Ev GCOBOL_TEMPDIR .
1467 If the value is just
1468 .Dq / ,
1469 the effect is different: each copybook read is reported on standard
1470 error. This feature is meant to help diagnose mysterious copybook
1471 errors.
1472 .El
1473 .
1474 .Sh FILES
1475 Executables produced by
1476 .Nm
1477 require the runtime support library
1478 .Pa libgcobol ,
1479 which is provided both as a static library and as a shared object.
1480 .
1481 .\" .Sh DIAGNOSTICS
1482 .
1483 .Sh COMPATIBILITY
1484 The ISO standard leaves the default file organization up to the implementation; in
1485 .Nm ,
1486 the default is
1487 .Sy "SEQUENTIAL" .
1488 .
1489 .Ss On-Disk Format
1490 Any ability to use files produced by other \*[lang] compilers, or for
1491 those compilers to use files produced by
1492 .Nm ,
1493 is the product of luck and intuition. Various compilers interpret the
1494 ISO standard differently, and the standard's text is
1495 not always definitive.
1496 .Pp
1497 For
1498 .Sy "ORGANIZATION IS LINE SEQUENTIAL"
1499 files (explicitly or by default),
1500 .Nm ,
1501 absent specific direction, produces an ordinary Linux text file: for
1502 each WRITE, the data are written, followed by an ASCII NL (hex 0A)
1503 character. On READ, the record is read up to the size of the
1504 specified record or NL, whichever comes first. The NL is not included
1505 in the data brought into the record buffer; it serves only as an
1506 on-disk record-termination marker. Consequently,
1507 .Sy SEQUENTIAL
1508 and
1509 .Sy "LINE SEQUENTIAL"
1510 files work the same way: the \*[lang] program never sees the record
1511 terminator.
1512 .Pp
1513 When
1514 .Sy READ
1515 and
1516 .Sy WRITE
1517 are used with
1518 .Sy ADVANCING ,
1519 however, the game changes. If
1520 .Sy ADVANCING
1521 is used with
1522 .Sy "LINE SEQUENTIAL"
1523 files,
1524 it is honored by
1525 .Nm .
1526 .Pp
1527 Other compilers may not do likewise.
1528 According to ISO, in
1529 .Sy WRITE
1530 (14.9.47.3 General rules)
1531 .Sy ADVANCING
1532 is
1533 .Em ignored
1534 for files for which
1535 .Dq "the physical file does not support vertical positioning" .
1536 It further states that, in the absence of
1537 .Sy ADVANCING ,
1538 .Sy WRITE
1539 proceeds as if
1540 .Dq "as if the user has specified AFTER ADVANCING 1 LINE" .
1541 Some other implementations interpret that to mean that the first
1542 .Sy WRITE
1543 to a
1544 .Sy "LINE SEQUENTIAL"
1545 file results in a leading NL on the first line, and no trailing NL on
1546 the last line. Some furthermore
1547 .Em prohibit
1548 the use of
1549 .Sy ADVANCING
1550 with
1551 .Sy "LINE SEQUENTIAL"
1552 files.
1553 .
1554 .\" .Sh SEE ALSO
1555 .
1556 .Sh STANDARDS
1557 The reference standard for
1558 .Nm
1559 is \*[isostd].
1560 .Bl -bullet -compact
1561 .It
1562 If
1563 .Nm
1564 compiles code consistent with that standard, the resulting program
1565 should execute correctly; any other result is a bug.
1566 .It
1567 If
1568 .Nm
1569 compiles code that does not comply with that standard, but runs correctly according to some other specification, that represents a non-standard extension. One day, the
1570 .Fl pedantic
1571 option will produce diagnostic messages for such code.
1572 .It
1573 If
1574 .Nm
1575 rejects code consistent with that standard, that represents an aspect
1576 of \*[lang] that is (or is not) on the To Do list. If you would like
1577 to see it compile, please get in touch with the developers.
1578 .El
1579 .
1580 .Ss Status of NIST \*[lang] Compiler Verification Suite
1581 .Bl -tag -compact -width "\0\0100% NC"
1582 .It NC 100%
1583 Nucleus
1584 .It SQ 100%
1585 Sequential I/O
1586 .It RL 100%
1587 Relative I/O
1588 .It IX 100%
1589 Indexed I/O
1590 .It IC 100%
1591 Inter-Program Communication
1592 .It ST 100%
1593 Sort-Merge
1594 .It SM 100%
1595 Source Text Manipulation RW \en Report Writer
1596 .It CM
1597 Communication
1598 .It DB to do?
1599 Debug
1600 .It SG
1601 Segmentation
1602 .It IF 100%
1603 Intrinsic Function
1604 .El
1605 .Pp
1606 Where
1607 .Nm
1608 passes 100% of the tests in a module, we exclude the (few) tests for
1609 obsolete features. The authors regard features that were obsolete in
1610 1985 to be well and truly obsolete today, and did not implement them.
1611 .
1612 .Ss Notable deferred features
1613 CCVS-85 modules not marked with above with any status (CM, and SG) are on the
1614 .Dq "hard maybe"
1615 list, meaning they await an interested party with real code using the feature.
1616 .Pp
1617 .Nm
1618 does not implement Report Writer or Screen Section.
1619 .
1620 .Ss Beyond COBOL/85
1621 .Nm
1622 increasingly implements \*[isostd]. For example,
1623 .Sy DECLARATIVES
1624 is not tested by CCVS-85, but are implemented by
1625 .Nm Ns .
1626 Similarly, Exception Conditions were not defined in 1985, and
1627 .Nm
1628 contains a growing number of them.
1629 .Pp
1630 The authors are well aware that a complete, pure \*[lang]-85 compiler
1631 won't compile most existing \*[lang] code. Every vendor offered (and
1632 offers) extensions, and most environments rely on a variety of
1633 preprocessors and ancillary systems defined outside the standard. The
1634 express goal of adding an ISO \*[lang] front-end to GCC is to establish a
1635 foundation on which any needed extensions can be built.
1636 .
1637 .Sh HISTORY
1638 \*[lang], the language, may well be older than the reader. To the
1639 author's knowledge, free \*[lang] compilers first began to appear in 2000.
1640 Around that time an earlier \*[lang] for GCC project
1641 .br
1642 .Lk https://cobolforgcc.sourceforge.net/ cobolforgcc
1643 met with some success, but was never officially merged into GCC.
1644 .Pp
1645 This compiler,
1646 .Nm ,
1647 was begun by
1648 .Lk https://www.cobolworx.com/ COBOLworx
1649 in the fall of 2021. The
1650 project announced a complete implementation of the core language
1651 features in December 2022.
1652 .
1653 .Sh AUTHORS
1654 .Bl -tag -compact
1655 .It "James K. Lowden"
1656 ([email protected]) is responsible for the parser.
1657 .It "Robert Dubner"
1658 ([email protected]) is responsible for producing the GIMPLE tree,
1659 which is input to the GCC back-end.
1660 .El
1661 .
1662 .Sh CAVEATS
1663 .Bl -bullet -compact
1664 .It
1665 .Nm
1666 has been tested only on x64 and Apple M1 processors running Linux in
1667 64-bit mode.
1668 .It
1669 The I/O support has not been extensively tested, and does not
1670 implement or emulate many features related to VSAM and other mainframe
1671 subsystems. While LINE-SEQUENTIAL files are ordinary text files that
1672 can be manipulated with standard utilities, INDEXED and RELATIVE files
1673 produced by
1674 .Nm
1675 are not compatible with that of any other \*[lang] compiler. Enhancements
1676 to the I/O support will be readily available to the paying customer.
1677 .El
1678 .
1679 .\" .Sh BUGS