Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

Appendix: KR or ANSI functionality

&pagelevel(2)&pagelevel

All details presented in this section apply to the functions marked with xx in the table on "Scope of the supported C library" (Scope of the supported C library).

When the C library functions were first introduced with C V1.0, the ANSI-defined C library scope did not exist. The implementation was therefore based on the "provisional" definition by Kernighan & Ritchie ("KR") and on the commercially available UNIX implementations.

The alignment of the original C library functions to the ANSI standard (C V2.0) has led to a few deviations in the execution of some I/O functions as compared with the predecessor version. In order to meet the requirements of the ANSI standard in full on one hand, while preserving the runtime behavior of "old-style" programs on the other, the I/O functions affected by these deviations in C/C++ versions V2.xx are now offered in two variants:
with the new ANSI functionality and with the original "KR" functionality compatible with
C V1.0.

The desired functionality is selected at compile time with the following compiler option:

SOURCE-PROPERTIES=PAR(LIBRARY-SEMANTICS=STD|V1-COMPATIBLE)

KR functionality (V1-COMPATIBLE) can only be selected in the KR and ANSI compilation modes. In the STRICT-ANSI and CPLUSPLUS compilation modes, the V1-COMPATIBLE specification is ignored, and STD is automatically assumed.
KR or ANSI functionality applies to the calls of all the library functions of a compilation unit.

Important

If the same file is processed in a number of separately compiled source programs, these source programs must be compiled with the same LIBRARY-SEMANTICS parameter!

KR functionality cannot be enabled when programs are developed in the POSIX shell. In other words, all the I/O functions are always executed with ANSI functionality.

As of C/C++ V3.0 the KR functionality is no longer available.

The differences between KR and ANSI functionality are listed below.

KR functionality

  1. Default attributes of text files
    When a new text file is created, it is generated as a SAM file with variable record length.

  2. Location of the file position indicator in append mode
    If the file position indicator of a file opened in append mode was explicitly moved from the end of the file (with rewind(), fsetpos(), fseek(), or lseek()), it will be automatically reset to the end of the file only when writing with the elementary function write().

    When a file is opened in append mode and for reading, the file position indicator will be set to the end of the file when the file is opened. The original contents of existing files are preserved.

  3. ISAM files (flushing of buffers)
    If the data of an ISAM file in the buffer does not end with a newline character, writing to the external file causes a change of record. Subsequent data is written to a new record.

  4. ungetc()
    When the contents of the buffer are written to the external file, the original data will be changed if a character other than the last character read was pushed back in the buffer.

  5. Interpretation of the tab character (\t)
    For output to text files of FCB type SAM or ISAM, the tab character is converted by default into the appropriate number of blanks.

  6. fprintf(), printf(), sprintf(), fscanf(), scanf(), sscanf()The ANSI extensions of the formatting and conversion characters are not available. The syntax and semantics of the predecessor version apply.

  7. vfprintf(), vprintf(), vsprintf()
    The conversion character L cannot be used, since the type long double is not supported in KR mode.

ANSI functionality

  1. Default attributes of text files
    When a new text file is created, it is generated as a ISAM file with variable record length.

  2. Location of the file position indicator in append mode
    If the file position indicator of a file opened in append mode was explicitly moved from the end of the file (with rewind(), fsetpos(), fseek(), or lseek()), the current position will be ignored for all write functions, and the file position indicator will be automatically set to the end of the file.

    When a file is opened in append mode and for reading, the file position indicator will be set to the end of the file when the file is opened. The original contents of existing files are preserved.

  3. ISAM files (flushing of buffers)
    If the data of an ISAM file in the buffer does not end with a newline character, writing to the external file does not cause a change of record. Subsequent data extends the record in the file. In other words, when reading an ISAM file, only the newline characters explicitly written by the program are read.

    If reading from any text file requires a data transfer from the external file to the internal C buffer, all ISAM file data that still in the buffer will be automatically written out to the files.

  4. ungetc()
    When the contents of the buffer are written to the external file, the original data will not be changed if a character other than the last character read was pushed back in the buffer. The original data before the ungetc call is always written to the external file.

  5. Interpretation of the tab character (\t)
    For output to text files of FCB type SAM or ISAM, the tab character is not converted by default into the appropriate number of blanks, but is written to the file as a text character (EBCDIC value).