]> zdv2.bktei.com Git - BK-2023-05.git/blob - src/notes.tm
0d4cac65d7c447da26bf10a84a3094b2b31007e4
[BK-2023-05.git] / src / notes.tm
1 <TeXmacs|2.1.1>
2
3 <style|<tuple|book|style-bk>>
4
5 <\body>
6 <\hide-preamble>
7 \;
8
9 <assign|description-aligned|<\macro|body>
10 <compound|<if|<and|<value|<merge|prefix-|description-aligned>>|<unequal|<value|last-item-nr>|0>>|list*|list>|<macro|name|<aligned-item|<item-strong|<arg|name><item-spc>>>>|<macro|name|<with|mode|math|<with|font-series|bold|math-font-series|bold|<rigid|\<ast\>>>>>|<arg|body>>
11 </macro>>
12 </hide-preamble>
13
14 <chapter|Definitions>
15
16 <section|Terminology>
17
18 <\description-compact>
19 <item*|assignment>An expression in which a variable is set to a value.
20 For example, in the expression <hgroup|<cpp|x = 1>>, the variable <cpp|x>
21 is set to the value <cpp|1> because <cpp|x> is to the left of the equals
22 sign \ \P<cpp|=>\Q. The value of the entire expression is equal to the
23 value of the left hand side (i.e. <cpp|x> in this example) after the
24 assignment is performed. For example, the following C code will print
25 \P<cpp|true>\Q:
26
27 <\cpp-code>
28 #include \<less\>stdio.h\<gtr\>
29
30 int main() {
31
32 \ \ int c;
33
34 \ \ if( (c = 7) == 7 )
35
36 \ \ \ \ printf("true");
37
38 \ \ else
39
40 \ \ \ \ printf("false");
41
42 };
43 </cpp-code>
44
45 As another example, the following lines are equivalent:
46
47 <\cpp-code>
48 a = b = c = 0;
49
50 a = ( b = ( c = 0 ) );
51 </cpp-code>
52
53 <item*|declaration<label|term declaration>>A construct that establishes
54 an association between a particular variable, function, or type and its
55 attributes. (See <hlink|cppreference.com|https://en.cppreference.com/w/c/language/declarations>
56 and <hlink|microsoft.com|https://docs.microsoft.com/en-us/cpp/c-language/c-declarations-and-definitions>).
57 Compare with <with|font-series|bold|definition>.
58
59 <item*|definition<label|term definition>>A construct that stablishes the
60 same associations as a declaration but also causes storage to be
61 allocated for the variable. (See <hlink|microsoft.com|https://docs.microsoft.com/en-us/cpp/c-language/c-declarations-and-definitions>).
62
63 <item*|enumeration<label|term enumeration>><hlink|Enumeration|https://en.wikipedia.org/wiki/Enumeration>
64 (or <code*|enum>) is a user defined data type in <name|C>. It is mainly
65 used to assign names to integral constants. For example, the declaration
66 <code*|enum year{Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov,
67 Dec};> allows writing a for loop with names of months <code*|for (i=Jan;
68 i\<less\>=Dec; i++)> to cycle <code*|i> through the integers <code*|0, 1,
69 2, 3, <text-dots>, 10, 11>.
70
71 <item*|escape sequence<label|term escape_sequence>>A set of characters
72 used to represent hard-to-type or invisible characters. Some commonly
73 used escape sequences in <name|C> include:
74
75 <\description-aligned>
76 <item*|<cpp|\\n>>Represents the <em|newline> character.
77
78 <item*|<cpp|\\t>>Represents the <em|tab> character.
79
80 <item*|<cpp|\\b>>Represents the <em|backspace> character.
81
82 <item*|<cpp|\\\\>>Represents the <em|backslash> (i.e.
83 \P<verbatim|<em|\\>>\Q) character.
84 </description-aligned>
85
86 All other escape sequences used in <name|C> are:
87
88 <\description-aligned>
89 <item*|<cpp|\\a>>Represents the <em|alert> (bell) character.
90
91 <item*|<cpp|\\f>>Represents the <em|formfeed> character.
92
93 <item*|<cpp|\\r>>Represents the <em|carriage return> character.
94
95 <item*|<cpp|\\t>>Represents the <em|horizontal tab> character.
96
97 <item*|<cpp|\\v>>Represents the <em|vertical tab> character.
98
99 <item*|<cpp|\\?>>Represents the <em|question mark> character.
100
101 <item*|<cpp|\\'>>Represents the <em|single quote> character.
102
103 <item*|<cpp|\\">>Represents the <em|double quote> character.
104
105 <item*|<cpp|\\><em|ooo>>Represents an <em|octal number> (e.g.
106 <cpp|\\012> is the <em|newline> character<\footnote>
107 <label|ref includehelp-oct-hex>See
108 <hlinkv|https://www.includehelp.com/c/octal-and-hexadecimal-escape-sequences.aspx>.
109 </footnote>).
110
111 <item*|<cpp|\\x><em|hh>>Represents a <em|hexadecimal> number (e.g.
112 <cpp|\\x0A> is the <em|newline> character<rsup|<reference|ref
113 includehelp-oct-hex>>).
114 </description-aligned>
115
116 <label|term garbage_collection><item*|garbage collection>The process of
117 freeing memory allocated by a program but which is no longer referenced.
118 Usually incurs a significant <hlink|speed
119 penalty|https://en.wikipedia.org/wiki/Overhead_(computing)>.
120 (<hlink|Wikipedia|https://en.wikipedia.org/wiki/Garbage_collection_(computer_science)>).
121 The <name|C> Language does not provide garbage collection by default.
122
123 <item*|<label|term heap>heap>A large pool of memory that can be used
124 dynamically \U it is also known as the \Pfree store\Q. This is memory
125 that is not automatically managed \U you have to explicitly allocate
126 (using functions such as malloc), and deallocate (e.g. free) the memory.
127 Failure to free the memory when you are finished with it will result in
128 what is known as a memory leak. Is the diametrical opposite of the stack
129 (which, by contrast, is limited not by physical memory but by a
130 CPU-determined stack size). (See <hlink|craftofcoding.wordpress.com|https://craftofcoding.wordpress.com/2015/12/07/memory-in-c-the-stack-the-heap-and-static/>).
131
132 <item*|<label|term machine-independent>machine-independent>A property of
133 code that does not have to be modified in order to run on a different
134 hardware architecture. (e.g. \PC is called a portable language because
135 [code written in C] will run on any machine which supports C, without
136 modifying a single line of code.\Q; <hlink|link|https://www.log2base2.com/C/basic/introduction-to-c-language.html>).
137
138 <item*|<label|term operand>operand>A quantity to which an operator is
139 applied. (e.g. in the <name|C> math expression <code*|7 - 4 = 3>,
140 <code*|7> is the first operand and <code*|4> is the second operand.)
141
142 <item*|<label|term operator>operator>A special type of function with
143 limited numbers of parameters (e.g. 1 to 2) and syntax often requiring a
144 set of characters different from those normally use for naming variables
145 (e.g. the <code*|+> character in <code*|myVar = 1 + 2>, the <code*|&&> in
146 <code*|a && b>, or the <code*|++> in <code*|i++>.).
147
148 <item*|<label|term stack>stack>A region of memory for global variable
149 storage and is permanent for the entire run of the program. Stack size is
150 limited not by physical memory availability but by the CPU. Lifetime of
151 local variables declared within the stack is enforced by the Last-In,
152 First-Out nature of the stack; when a function returns a value, all stack
153 memory allocated by declarations within the function is automatically
154 freed. (See <hlink|craftofcoding.wordpress.com|https://craftofcoding.wordpress.com/2015/12/07/memory-in-c-the-stack-the-heap-and-static/>)
155
156 <item*|<label|term struct>struct>(short:
157 <hlink|struct|https://en.wikipedia.org/wiki/struct_(C_programming_language)>)
158 a <hlink|composite data type|https://en.wikipedia.org/wiki/Composite_data_type>
159 that defines a physically grouped list of variables under one name in a
160 block of memory, allowing the different variables to be accessed via a
161 single <hlink|pointer|https://en.wikipedia.org/wiki/Pointer_(computer_programming)>
162 or by the struct declared name which returns the same address.
163
164 <label|term structure_assignment><item*|structure assignment>The act of
165 <hlink|assigning|https://en.wikipedia.org/wiki/Assignment_(computer_science)>
166 a <hlink|struct|https://en.wikipedia.org/wiki/struct_(C_programming_language)>
167 to another struct. (?) (<hlink|example|https://stackoverflow.com/a/2302359/10850071>)
168
169 <item*|<label|term text_stream>text stream>A sequence of characters
170 divided into lines; each line consists of zero or more characters
171 followed by a newline character. (See K&R 2nd Ed. Section 1.5 \PCharacter
172 Input and Output\Q)
173 </description-compact>
174
175 \;
176
177 <section|Functions>
178
179 <subsection|Character Input and Output>
180
181 <\description>
182 <item*|<cpp|getchar()><label|func getchar>>Read one character at a time
183 from the input buffer. Returns as <cpp|int> a <em|character
184 constant>.<\footnote>
185 <name|ASCII> characters have constants in the range <math|0-127>. UTF-8
186 characters return multiple constants (e.g. \<#B0\> returns <cpp|194
187 176>). See <hlinkv|https://www.smashingmagazine.com/2012/06/all-about-unicode-utf8-character-sets/>.
188 A strategy for reading the multiple bytes of a UTF-8 character is here:
189 <hlinkv|https://stackoverflow.com/a/34240796/>.
190 </footnote>
191
192 <item*|<cpp|for()>>A generalization of <cpp|while()>. Takes three
193 arguments:
194
195 <\enumerate>
196 <item>Local statement to run before loop (e.g. to initialize a counting
197 variable).
198
199 <item>Local statement that, if evaluated as true, permits running of
200 next iteration of loop.
201
202 <item>Local statement to run after loop (e.g. to increment a counting
203 variable).
204 </enumerate>
205
206 <item*|<cpp|putchar(int arg1)><label|func putchar>>Write one integer
207 character (e.g. <cpp|arg1>) at a time.
208
209 <item*|<cpp|printf()>>Used for printing formatted text to console.
210
211 Character codes include:
212
213 <\description-aligned>
214 <item*|<cpp|%d>>Used with <cpp|int> (i.e. 16-bit integers; max value of
215 <math|2<rsup|16>=32\<space\>767>).
216
217 <item*|<cpp|%ld>>Used with <cpp|long> (i.e. at least 32-bit
218 integers).<\footnote>
219 K&R 2nd Ed., Sec. 1.5 \PThe conversion specification <cpp|%ld> tells
220 <cpp|printf> that the corresponding argument is a <cpp|long>
221 integer.\Q
222 </footnote>
223
224 <item*|<cpp|%f>>Used with <cpp|float> and <cpp|double> (double
225 precision <cpp|float>).
226 </description-aligned>
227 </description>
228
229 \;
230
231 \;
232
233 \;
234 </body>
235
236 <\initial>
237 <\collection>
238 <associate|preamble|false>
239 </collection>
240 </initial>
241
242 <\references>
243 <\collection>
244 <associate|auto-1|<tuple|1|?>>
245 <associate|auto-2|<tuple|1.1|?>>
246 <associate|auto-3|<tuple|1.2|?>>
247 <associate|auto-4|<tuple|1.2.1|?>>
248 <associate|footnote-1|<tuple|1|?>>
249 <associate|footnote-1.1.1|<tuple|1.1.1|?>>
250 <associate|footnote-1.2.1|<tuple|1.2.1|?>>
251 <associate|footnote-1.2.2|<tuple|1.2.2|?>>
252 <associate|footnr-1.1.1|<tuple|1.1.1|?>>
253 <associate|footnr-1.2.1|<tuple|1.2.1|?>>
254 <associate|footnr-1.2.2|<tuple|1.2.2|?>>
255 <associate|func getchar|<tuple|1.2.1|?>>
256 <associate|func putchar|<tuple|3|?>>
257 <associate|ref includehelp-oct-hex|<tuple|1.1.1|?>>
258 <associate|term declaration|<tuple|assignment|?>>
259 <associate|term definition|<tuple|declaration<label|term declaration>|?>>
260 <associate|term enumeration|<tuple|definition<label|term definition>|?>>
261 <associate|term escape_sequence|<tuple|enumeration<label|term
262 enumeration>|?>>
263 <associate|term garbage_collection|<tuple|<with|mode|<quote|prog>|prog-language|<quote|cpp>|font-family|<quote|rm>|\\x><with|font-shape|<quote|italic>|hh>|?>>
264 <associate|term heap|<tuple|garbage collection|?>>
265 <associate|term machine-independent|<tuple|<label|term heap>heap|?>>
266 <associate|term operand|<tuple|<label|term
267 machine-independent>machine-independent|?>>
268 <associate|term operator|<tuple|<label|term operand>operand|?>>
269 <associate|term stack|<tuple|<label|term operator>operator|?>>
270 <associate|term struct|<tuple|<label|term stack>stack|?>>
271 <associate|term structure_assignment|<tuple|<label|term struct>struct|?>>
272 <associate|term text_stream|<tuple|structure assignment|?>>
273 </collection>
274 </references>
275
276 <\auxiliary>
277 <\collection>
278 <\associate|toc>
279 <vspace*|1fn><with|font-series|<quote|bold>|math-font-series|<quote|bold>|1<space|2spc>Definitions>
280 <datoms|<macro|x|<repeat|<arg|x>|<with|font-series|medium|<with|font-size|1|<space|0.2fn>.<space|0.2fn>>>>>|<htab|5mm>>
281 <no-break><pageref|auto-1><vspace|0.5fn>
282
283 1.1<space|2spc>Terminology <datoms|<macro|x|<repeat|<arg|x>|<with|font-series|medium|<with|font-size|1|<space|0.2fn>.<space|0.2fn>>>>>|<htab|5mm>>
284 <no-break><pageref|auto-2>
285
286 1.2<space|2spc>Functions <datoms|<macro|x|<repeat|<arg|x>|<with|font-series|medium|<with|font-size|1|<space|0.2fn>.<space|0.2fn>>>>>|<htab|5mm>>
287 <no-break><pageref|auto-3>
288
289 <with|par-left|<quote|1tab>|1.2.1<space|2spc>Character Input and Output
290 <datoms|<macro|x|<repeat|<arg|x>|<with|font-series|medium|<with|font-size|1|<space|0.2fn>.<space|0.2fn>>>>>|<htab|5mm>>
291 <no-break><pageref|auto-4>>
292 </associate>
293 </collection>
294 </auxiliary>