annotate docs/ccguide/chap4.chapter @ 3295:6b7a7b233925 default tip

makefile: Allow PORTS with level1/2 mix https://sourceforge.net/p/nitros9/feature-requests/10/
author Tormod Volden <debian.tormod@gmail.com>
date Tue, 19 Apr 2022 18:12:17 +0200
parents 497d17b4b264
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
466
bea58398bb15 Skeletons for the C Compiler User's Guide, 1983
roug
parents:
diff changeset
1 <chapter>
bea58398bb15 Skeletons for the C Compiler User's Guide, 1983
roug
parents:
diff changeset
2 <title>C Standard Library</title>
bea58398bb15 Skeletons for the C Compiler User's Guide, 1983
roug
parents:
diff changeset
3 <para>
bea58398bb15 Skeletons for the C Compiler User's Guide, 1983
roug
parents:
diff changeset
4 The Standard Library contains functions which fall into two
bea58398bb15 Skeletons for the C Compiler User's Guide, 1983
roug
parents:
diff changeset
5 classes: high-level I/O and convenience.
bea58398bb15 Skeletons for the C Compiler User's Guide, 1983
roug
parents:
diff changeset
6 </para>
468
60b821f18853 A little here and there.
roug
parents: 466
diff changeset
7 <para>
60b821f18853 A little here and there.
roug
parents: 466
diff changeset
8 The high-level I/O functions provide facilities that are
60b821f18853 A little here and there.
roug
parents: 466
diff changeset
9 normally considered part of the definition of other languages; for
60b821f18853 A little here and there.
roug
parents: 466
diff changeset
10 example, the FORMAT "statement" of Fortran. In addition, automatic
60b821f18853 A little here and there.
roug
parents: 466
diff changeset
11 buffering of I/O channels improves the speed of file access because
60b821f18853 A little here and there.
roug
parents: 466
diff changeset
12 fewer system calls are necessary.
60b821f18853 A little here and there.
roug
parents: 466
diff changeset
13 </para>
610
497d17b4b264 Finished all the error messages in appendix A
roug
parents: 570
diff changeset
14 <para>
497d17b4b264 Finished all the error messages in appendix A
roug
parents: 570
diff changeset
15 The high-level I/O functions should not be confused with the
497d17b4b264 Finished all the error messages in appendix A
roug
parents: 570
diff changeset
16 low-level system calls with similar names. Nor shoul "file
497d17b4b264 Finished all the error messages in appendix A
roug
parents: 570
diff changeset
17 pointers" be confused with "path numbers". The standard library
497d17b4b264 Finished all the error messages in appendix A
roug
parents: 570
diff changeset
18 functions maintain a structure for each file open that holds status
497d17b4b264 Finished all the error messages in appendix A
roug
parents: 570
diff changeset
19 information and a pointer into the files buffer, A user program
497d17b4b264 Finished all the error messages in appendix A
roug
parents: 570
diff changeset
20 uses a pointer to this structure as the "identity" of the file
497d17b4b264 Finished all the error messages in appendix A
roug
parents: 570
diff changeset
21 (which is provided by "fopen()"), and passes it to the various
497d17b4b264 Finished all the error messages in appendix A
roug
parents: 570
diff changeset
22 I/O functions. The I/O functions will make the low-level system
497d17b4b264 Finished all the error messages in appendix A
roug
parents: 570
diff changeset
23 calls when necessary.
497d17b4b264 Finished all the error messages in appendix A
roug
parents: 570
diff changeset
24 </para>
497d17b4b264 Finished all the error messages in appendix A
roug
parents: 570
diff changeset
25 <para>
497d17b4b264 Finished all the error messages in appendix A
roug
parents: 570
diff changeset
26 <emphasis>Using a file pointer in a systen call, or a path number in a
497d17b4b264 Finished all the error messages in appendix A
roug
parents: 570
diff changeset
27 Standard Library call</emphasis>, is a common mistake among beginners to C and,
497d17b4b264 Finished all the error messages in appendix A
roug
parents: 570
diff changeset
28 if made, will be sure to <emphasis>crash your program.</emphasis>
497d17b4b264 Finished all the error messages in appendix A
roug
parents: 570
diff changeset
29 </para>
497d17b4b264 Finished all the error messages in appendix A
roug
parents: 570
diff changeset
30 <para>
497d17b4b264 Finished all the error messages in appendix A
roug
parents: 570
diff changeset
31 The convenience functions include facilities for copying,
497d17b4b264 Finished all the error messages in appendix A
roug
parents: 570
diff changeset
32 comparing, and concatening strings, converting numbers to strings,
497d17b4b264 Finished all the error messages in appendix A
roug
parents: 570
diff changeset
33 and doing the extra work in accessing systen information such as the
497d17b4b264 Finished all the error messages in appendix A
roug
parents: 570
diff changeset
34 time.
497d17b4b264 Finished all the error messages in appendix A
roug
parents: 570
diff changeset
35 </para>
497d17b4b264 Finished all the error messages in appendix A
roug
parents: 570
diff changeset
36 <para>
497d17b4b264 Finished all the error messages in appendix A
roug
parents: 570
diff changeset
37 In the page which follow, the functions available are
497d17b4b264 Finished all the error messages in appendix A
roug
parents: 570
diff changeset
38 described in terms of what they do and the parameters they expect.
497d17b4b264 Finished all the error messages in appendix A
roug
parents: 570
diff changeset
39 The "USAGE" section shows the name of the function and the type
497d17b4b264 Finished all the error messages in appendix A
roug
parents: 570
diff changeset
40 returned (if not int). The declaration of arguments are shown as
497d17b4b264 Finished all the error messages in appendix A
roug
parents: 570
diff changeset
41 they would be written in the function definition to indicate the
497d17b4b264 Finished all the error messages in appendix A
roug
parents: 570
diff changeset
42 types expected by the function. If it is necesary to include a
497d17b4b264 Finished all the error messages in appendix A
roug
parents: 570
diff changeset
43 file before the function can be used, it is shown in the "USAGE"
497d17b4b264 Finished all the error messages in appendix A
roug
parents: 570
diff changeset
44 section by "#include &lt;filename&gt;".
497d17b4b264 Finished all the error messages in appendix A
roug
parents: 570
diff changeset
45 </para>
497d17b4b264 Finished all the error messages in appendix A
roug
parents: 570
diff changeset
46 <para>
497d17b4b264 Finished all the error messages in appendix A
roug
parents: 570
diff changeset
47 Most of the header files that are required to be included, must
497d17b4b264 Finished all the error messages in appendix A
roug
parents: 570
diff changeset
48 reside in the "DEFS" directory on the default system drive. If the
497d17b4b264 Finished all the error messages in appendix A
roug
parents: 570
diff changeset
49 file is included in the source program using angle bracket
497d17b4b264 Finished all the error messages in appendix A
roug
parents: 570
diff changeset
50 delimiters instead of the usual double quotes, the compiler will
497d17b4b264 Finished all the error messages in appendix A
roug
parents: 570
diff changeset
51 append this path name to the file name. For example, "#include &lt;stdio.h&gt;"
497d17b4b264 Finished all the error messages in appendix A
roug
parents: 570
diff changeset
52 is equivalent to "#include &lt;/d0/defs/stdio.h&gt;", if "/d0" is
497d17b4b264 Finished all the error messages in appendix A
roug
parents: 570
diff changeset
53 the path name of the default system drive.
497d17b4b264 Finished all the error messages in appendix A
roug
parents: 570
diff changeset
54 </para>
497d17b4b264 Finished all the error messages in appendix A
roug
parents: 570
diff changeset
55 <para>
497d17b4b264 Finished all the error messages in appendix A
roug
parents: 570
diff changeset
56 <emphasis>Please note</emphasis> that if the type of the valye returned by a
497d17b4b264 Finished all the error messages in appendix A
roug
parents: 570
diff changeset
57 function is not INT, you should make a pre-declaration in your
497d17b4b264 Finished all the error messages in appendix A
roug
parents: 570
diff changeset
58 program before calling it. For example, if you wish to use
497d17b4b264 Finished all the error messages in appendix A
roug
parents: 570
diff changeset
59 "atof()", you should pre-declare by having "double atof();"
497d17b4b264 Finished all the error messages in appendix A
roug
parents: 570
diff changeset
60 somewhere in your program before a call to it. Some functions
497d17b4b264 Finished all the error messages in appendix A
roug
parents: 570
diff changeset
61 which have associated header files in the DEFS directory that
497d17b4b264 Finished all the error messages in appendix A
roug
parents: 570
diff changeset
62 should be included, will be pre-declared for you in the header. An
497d17b4b264 Finished all the error messages in appendix A
roug
parents: 570
diff changeset
63 example of this is "ftell()" which is pre-declared in "stdio.h". If
497d17b4b264 Finished all the error messages in appendix A
roug
parents: 570
diff changeset
64 you are in any doubt, read the header file.
497d17b4b264 Finished all the error messages in appendix A
roug
parents: 570
diff changeset
65 </para>
466
bea58398bb15 Skeletons for the C Compiler User's Guide, 1983
roug
parents:
diff changeset
66
bea58398bb15 Skeletons for the C Compiler User's Guide, 1983
roug
parents:
diff changeset
67 &atofref;
570
253b6096ee01 All function prototypes are added.
roug
parents: 472
diff changeset
68 &fcloseref;
466
bea58398bb15 Skeletons for the C Compiler User's Guide, 1983
roug
parents:
diff changeset
69 &feofref;
bea58398bb15 Skeletons for the C Compiler User's Guide, 1983
roug
parents:
diff changeset
70 &findstrref;
bea58398bb15 Skeletons for the C Compiler User's Guide, 1983
roug
parents:
diff changeset
71 &fopenref;
bea58398bb15 Skeletons for the C Compiler User's Guide, 1983
roug
parents:
diff changeset
72 &freadref;
bea58398bb15 Skeletons for the C Compiler User's Guide, 1983
roug
parents:
diff changeset
73 &fseekref;
bea58398bb15 Skeletons for the C Compiler User's Guide, 1983
roug
parents:
diff changeset
74 &getcref;
bea58398bb15 Skeletons for the C Compiler User's Guide, 1983
roug
parents:
diff changeset
75 &getsref;
bea58398bb15 Skeletons for the C Compiler User's Guide, 1983
roug
parents:
diff changeset
76 &isalpharef;
bea58398bb15 Skeletons for the C Compiler User's Guide, 1983
roug
parents:
diff changeset
77 &l3tolref;
bea58398bb15 Skeletons for the C Compiler User's Guide, 1983
roug
parents:
diff changeset
78 &longjmpref;
bea58398bb15 Skeletons for the C Compiler User's Guide, 1983
roug
parents:
diff changeset
79 &mallocref;
bea58398bb15 Skeletons for the C Compiler User's Guide, 1983
roug
parents:
diff changeset
80 &mktempref;
472
f0c8d53e5a50 entered: chdir chmod qsort strass toupper tsleep wait
roug
parents: 468
diff changeset
81 &printfref;
466
bea58398bb15 Skeletons for the C Compiler User's Guide, 1983
roug
parents:
diff changeset
82 &putcref;
bea58398bb15 Skeletons for the C Compiler User's Guide, 1983
roug
parents:
diff changeset
83 &putsref;
bea58398bb15 Skeletons for the C Compiler User's Guide, 1983
roug
parents:
diff changeset
84 &qsortref;
bea58398bb15 Skeletons for the C Compiler User's Guide, 1983
roug
parents:
diff changeset
85 &scanfref;
bea58398bb15 Skeletons for the C Compiler User's Guide, 1983
roug
parents:
diff changeset
86 &setbufref;
bea58398bb15 Skeletons for the C Compiler User's Guide, 1983
roug
parents:
diff changeset
87 &sleepref;
bea58398bb15 Skeletons for the C Compiler User's Guide, 1983
roug
parents:
diff changeset
88 &strcatref;
bea58398bb15 Skeletons for the C Compiler User's Guide, 1983
roug
parents:
diff changeset
89 &systemref;
bea58398bb15 Skeletons for the C Compiler User's Guide, 1983
roug
parents:
diff changeset
90 &toupperref;
bea58398bb15 Skeletons for the C Compiler User's Guide, 1983
roug
parents:
diff changeset
91 &ungetcref;
bea58398bb15 Skeletons for the C Compiler User's Guide, 1983
roug
parents:
diff changeset
92 </chapter>