-

Changes

Jump to: navigation, search

Standard Libraries

63 bytes removed, 19:04, 30 July 2017
no edit summary
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.
== Binary I/O ==
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.
== Floating Point 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