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
Default attributes of text files
When a new text file is created, it is generated as a SAM file with variable record length.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 (withrewind()
,fsetpos()
,fseek()
, orlseek()
), it will be automatically reset to the end of the file only when writing with the elementary functionwrite()
.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.
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.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.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.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.vfprintf()
,vprintf()
,vsprintf()
The conversion characterL
cannot be used, since the typelong double
is not supported in KR mode.
ANSI functionality
Default attributes of text files
When a new text file is created, it is generated as a ISAM file with variable record length.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 (withrewind()
,fsetpos()
,fseek()
, orlseek()
), 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.
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.
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 theungetc
call is always written to the external file.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).