-

Changes

Jump to: navigation, search

Standard Libraries

58 bytes removed, 19:04, 30 July 2017
no edit summary
8.1. == Standard I/O==
C is a language which does not specify the I/O facilites in the language itself; rather all I/O is performed via library routines. In practice this results in I/O handling which is no less convenient than any other language, with
are listed in detail in a subsequent section of the manual.
8.2. == Compatibility==
The libraries supplied with HI-TECH C are highly compatible with the ANSI libraries, as well as the V7 UNIX libraries, both at the Standard I/O level and the UNIX system call level. The Standard I/O library is complete, and
conforms in all respects with the UNIX Standard I/O library. The library routines implementing UNIX system call like functions are as close as possible to those system calls, however there are some UNIX system calls that cannot be simulated on other systems, e.g. the link() operation. However the basic low level I/O routines, i.e. open, close, read, write and lseek are identical to the UNIX equivalents. This means that many programs written to run on UNIX, even if they do not use Standard I/O, will run with little modification when compiled with HI-TECH C.
8.3. == Libraries for Embedded Systems==
The cross compilers, designed to produce code for target systems without operating systems, are supplied with libraries implementing a subset of the STDIO functions. Not provided are those functions dealing with files. Included
are _�p_�r_�i_�n_�t_�f<strong>printf(), _�s_�c_�a_�n_�fscanf() </strong> etc. These operate by calling two low level functions _�p_�u_�t_�c_�h <strong>putch</strong> and _�g_�e_�t_�c_�h<strong>getch() </strong> which typically send and receive characters via a serial port. Where the compiler is aimed at a single-chip micro with on-board UART this is used. The source code for all these functions is supplied enabling the user to modify it to address a different serial port.
8.4. == Binary I/O==
On some operating systems, notably CP/M, files are treated differently according to whether they contain ASCII (i.e. printable) or binary data. MD-DOS also suffers from this problem, not due to any lack in the operating system
itself, but rather because of the hangover from CP/M which results in many programs putting a redundant ctrl-Z at the end of files. Unfortunately there is no way to determine which type of data a file contains (except perhaps by the name or type of the file, and this is not reliable). To overcome this difficulty, there is an extra character which may be included in the MODE string to a fopen() call. To open a file for ASCII I/O, the form of the fopen() call is:
fopen("filename.ext", "r") /* for reading */ fopen("filename.ext", "w") /* for writing */
To open a file for binary I/O, the character 'b' may be
appended to the
fopen("filename.ext", "rb") fopen("filename.ext", "wb")
routines:
;newline
:('\n') converted to carriage return/newline on output.
;return
:('\r') ignored on input
;Ctrl-Z
:interpreted as End-Of-File on input and, for CP/M only, appended when closing the file.
A mention here of the term `stream' is appropriate; stream is used in relation to the STDIO library routines to mean the source or sink of bytes (characters) manipulated by those routines. Thus the FILE pointer supplied as an argu-
ment to the STDIO routines may be regarded as a handle on the corresponding stream. A stream may be viewed as a featureless sequence of bytes, originating from or being sent to a device or file or even some other indeterminate source. A FILE pointer should not be confused with the 'file descriptors' used with the low-level I/O functions _�o_�p_�e_�n<strong>open(), _�c_�l_�o_�s_�eclose(), _�r_�e_�a_�dread() </strong> and _�w_�r_�i_�t_�e<strong>write()</strong>. These form an independent group of I/O functions which perform unbuffered reads and writes to files.
8.5. == Floating Point Library==
HI-TECH C supports floating point as part of the language, however the Z80 implementation provides single precision only; double floats are permitted but are no different to floats. In addition, the standard library,
Thus, if floating point is used, a -LF option should be used AFTER the source and/or object files to the C command. E.g.:
C -V -O x.c y.c z.obj -LF

Navigation menu