3 <style|<tuple|book|style-bk>>
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>>
18 <\description-compact>
19 <item*|argument<label|term_argument>>A value used to supply a
20 <strong|parameter> in the call of a <strong|function>. Also known as an
21 \Pactual argument\Q as opposed to \Pformal argument\Q (i.e.
22 <strong|parameter>). See also <em|parameter>.
24 <item*|assignment>An expression in which a variable is set to a value.
25 For example, in the expression <hgroup|<cpp|x = 1>>, the variable <cpp|x>
26 is set to the value <cpp|1> because <cpp|x> is to the left of the equals
27 sign \ \P<cpp|=>\Q. The value of the entire expression is equal to the
28 value of the left hand side (i.e. <cpp|x> in this example) after the
29 assignment is performed. For example, the following C code will print
33 #include \<less\>stdio.h\<gtr\>
39 \ \ if( (c = 7) == 7 )
41 \ \ \ \ printf("true");
45 \ \ \ \ printf("false");
50 As another example, the following lines are equivalent:
55 a = ( b = ( c = 0 ) );
58 <label|term_call><item*|call>The act of running (or \Pinvoking\Q) a
59 <strong|function>. See <em|function call>.
61 <label|term declaration><item*|declaration>A construct that establishes
62 an association between a particular variable, function, or type and its
64 See <hlinkv|https://en.cppreference.com/w/c/language/declarations>.
65 </footnote>. Announces the properties of variables. May be a statement
66 consisting of a <strong|type> name followed by a list of
67 <strong|variables> (e.g. <cpp|int i, j;>) or followed by an expression
68 with a variable (e.g. <cpp|int i = 0;>). Compare with
69 <with|font-series|bold|definition>.
71 <label|term definition><item*|definition>A construct that establishes the
72 same associations as a declaration but also causes storage to be
73 allocated for the variable<\footnote>
74 See <hlinkv|https://docs.microsoft.com/en-us/cpp/c-language/c-declarations-and-definitions?view=msvc-170>.
77 <label|term_linter><item*|linter> A source code analysis program designed
78 to detect common syntactic errors.
80 <label|term enumeration><item*|enumeration><hlink|Enumeration|https://en.wikipedia.org/wiki/Enumeration>
81 (or <code*|enum>) is a user defined data type in <name|C>. It is mainly
82 used to assign names to integral constants. For example, the declaration
83 <code*|enum year{Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov,
84 Dec};> allows writing a for loop with names of months <code*|for (i=Jan;
85 i\<less\>=Dec; i++)> to cycle <code*|i> through the integers <code*|0, 1,
86 2, 3, <text-dots>, 10, 11>.
88 <label|term escape_sequence><item*|escape sequence>A set of characters
89 used to represent hard-to-type or invisible characters. Some commonly
90 used escape sequences in <name|C> include:
92 <\description-aligned>
93 <item*|<cpp|\\n>>Represents the <em|newline> character.
95 <item*|<cpp|\\t>>Represents the <em|tab> character.
97 <item*|<cpp|\\b>>Represents the <em|backspace> character.
99 <item*|<cpp|\\\\>>Represents the <em|backslash> (i.e.
100 \P<verbatim|<em|\\>>\Q) character.
101 </description-aligned>
103 All other escape sequences used in <name|C> are:
105 <\description-aligned>
106 <item*|<cpp|\\a>>Represents the <em|alert> (bell) character.
108 <item*|<cpp|\\f>>Represents the <em|formfeed> character.
110 <item*|<cpp|\\r>>Represents the <em|carriage return> character.
112 <item*|<cpp|\\t>>Represents the <em|horizontal tab> character.
114 <item*|<cpp|\\v>>Represents the <em|vertical tab> character.
116 <item*|<cpp|\\?>>Represents the <em|question mark> character.
118 <item*|<cpp|\\'>>Represents the <em|single quote> character.
120 <item*|<cpp|\\">>Represents the <em|double quote> character.
122 <item*|<cpp|\\><em|ooo>>Represents an <em|octal number> (e.g.
123 <cpp|\\012> is the <em|newline> character)<\footnote>
124 <label|ref includehelp-oct-hex>See
125 <hlinkv|https://www.includehelp.com/c/octal-and-hexadecimal-escape-sequences.aspx>.
128 <item*|<cpp|\\x><em|hh>>Represents a <em|hexadecimal> number (e.g.
129 <cpp|\\x0A> is the <em|newline> character)<rsup|<reference|ref
130 includehelp-oct-hex>>.
132 <item*|<cpp|\\0>>Represents the <em|null> character (i.e. a <cpp|char>
133 with value <cpp|0>)<\footnote>
134 See <hlinkv|https://www.geeksforgeeks.org/difference-between-null-pointer-null-character-0-and-0-in-c-with-examples/>.
136 </description-aligned>
138 <label|term_expression><item*|expression> A sequence of
139 <strong|operators> and <strong|operands> that specify a computation. When
140 evaluated, an expression may perform useful side effects (e.g.
141 <cpp|printf("%d", 4)> sends the character <cpp|4> to \ the standard
142 output stream)<\footnote>
143 See <hlinkv|https://en.cppreference.com/w/c/language/expressions>.
146 Arrangements of expressions may include<\footnote>
147 See <hlinkv|https://www.educative.io/answers/what-are-expressions-in-c>.
151 <item*|Constant>A value with no operator is used<\footnote>
152 See <hlinkv|https://www.cs.miami.edu/home/burt/learning/Math120.1/Notes/exp-syn.html>.
153 </footnote>. (e.g. the \P<cpp|0>\Q in <cpp|return 0;>)
155 <item*|Variable identifier>A variable evaluated earlier. (e.g. the 2nd
156 \P<cpp|k>\Q in <hgroup|<cpp|k = 1; return k;>>)
158 <item*|Infix expression>Operator is used between operands. (e.g. <cpp|a
161 <item*|Postfix expression>Operator is used after the operands. (e.g.
164 <item*|Prefix expression>Operator is used before the operands. (e.g.
167 <item*|Unary expression>There is one operator and one operand. (e.g.
170 <item*|Binary expression>There is one operator and two operands. (e.g.
174 Types of expressions may include:
177 <item*|Arithmetic expression>Consists of arithmetic operators (<cpp|+,
178 -, *, and />) and computes values of <cpp|int, float, or double> type.
180 <item*|Relational expression>Usually uses comparison operators
181 (<cpp|\<gtr\>, \<less\>, \<gtr\>=, \<less\>=, ===, and !==>) and
182 computers answer in the <cpp|bool> type (i.e. true \P<cpp|1>\Q or false
185 <item*|Logical expression>Consists of logical operators (<cpp|&&, \|\|,
186 and !>) and combines relational expressions to compute answers in the
189 <item*|Conditional expression>Consists of statements that return
190 <cpp|true> if the condition is met or <cpp|false> otherwise.
192 <item*|Pointer expression>May consist of an ampersand (<cpp|&>)
193 operator and returns <cpp|address> values.
195 <item*|Bitwise expression>Consists of bitwise operators
196 (<cpp|\<gtr\>\<gtr\>, \<less\>\<less\>, ~, &, \|, and ^>) and performs
197 operations at the bit level.
199 <item*|Constant expression>Involves only constants such that the
200 expression may be evaluated during compilation rather than
202 K&R 2nd Ed., Sec. 2.3 \PConstants\Q.
206 <label|term_function><item*|function>A group of statements that perform a
207 task. Is defined using a function <strong|definition> that has a
208 parenthesized list of <strong|declarations> called <strong|parameters>
209 (e.g. variables for accepting values named <strong|arguments> as input
210 when the <strong|function> is called). A function definition has the
214 return-type<space|1em>function-name(parameter declarations, if any) {
216 <space|1em>declarations
218 <space|1em>statements
223 <label|term_function_call><item*|function call>An expression containing
224 the <strong|function> name followed by the function call operator
227 <label|term_function_prototype><item*|function prototype>A declaration of
228 a <strong|function> consisting only of the function name (a.k.a.
229 \Pidentifier\Q) and parenthesized <strong|parameter> types so the
230 compiler knows how to perform <strong|type>-based conversions of
231 <strong|arguments> (e.g. truncating a <cpp|float> into an <cpp|int>) in
232 <strong|calls> of the function before the compiler knows the function
233 <strong|definition><\footnote>
234 See <hlinkv|https://en.cppreference.com/w/c/language/function_declaration>.
235 </footnote>. The function prototype parameter names do not have to agree
236 with the function definition parameter names<\footnote>
237 K&R 2nd Ed., Sec 1.7 \PFunctions\Q.
240 <label|term garbage_collection><item*|garbage collection>The process of
241 freeing memory allocated by a program but which is no longer referenced.
242 Usually incurs a significant <hlink|speed
243 penalty|https://en.wikipedia.org/wiki/Overhead_(computing)>.
244 (<hlink|Wikipedia|https://en.wikipedia.org/wiki/Garbage_collection_(computer_science)>).
245 The <name|C> Language does not provide garbage collection by default.
247 <item*|<label|term heap>heap>A large pool of memory that can be used
248 dynamically \U it is also known as the \Pfree store\Q. This is memory
249 that is not automatically managed \U you have to explicitly allocate
250 (using functions such as malloc), and deallocate (e.g. free) the memory.
251 Failure to free the memory when you are finished with it will result in
252 what is known as a memory leak. Is the diametrical opposite of the stack
253 (which, by contrast, is limited not by physical memory but by a
254 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/>).
256 <item*|<label|term machine-independent>machine-independent>A property of
257 code that does not have to be modified in order to run on a different
258 hardware architecture. (e.g. \PC is called a portable language because
259 [code written in C] will run on any machine which supports C, without
260 modifying a single line of code.\Q; <hlink|link|https://www.log2base2.com/C/basic/introduction-to-c-language.html>).
262 <item*|<label|term operand>operand>A quantity to which an operator is
263 applied. (e.g. in the <name|C> math expression <code*|7 - 4 = 3>,
264 <code*|7> is the first operand and <code*|4> is the second operand.)
266 <item*|<label|term operator>operator>A special type of function with
267 limited numbers of parameters (e.g. 1 to 2) and syntax often requiring a
268 set of characters different from those normally use for naming variables
269 (e.g. the <code*|+> character in <code*|myVar = 1 + 2>, the <code*|&&> in
270 <code*|a && b>, or the <code*|++> in <code*|i++>.).
272 <label|term_parameter><item*|parameter>Generally, a variable named in the
273 parenthesized list in a <strong|function> definition. Also known as a
274 \Pformal argument\Q as opposed to an \Pactual argument\Q (e.g.
275 <strong|argument>). See <em|argument>.
277 <item*|<label|term stack>stack>A region of memory for global variable
278 storage and is permanent for the entire run of the program. Stack size is
279 limited not by physical memory availability but by the CPU. Lifetime of
280 local variables declared within the stack is enforced by the Last-In,
281 First-Out nature of the stack; when a function returns a value, all stack
282 memory allocated by declarations within the function is automatically
283 freed. (See <hlink|craftofcoding.wordpress.com|https://craftofcoding.wordpress.com/2015/12/07/memory-in-c-the-stack-the-heap-and-static/>)
285 <label|term_statement><item*|statement>An <strong|expression> when it is
286 followed by a semicolon. May be grouped together using braces (i.e.
287 \P<cpp|{ }>\Q) to form a <em|compound statement> or <em|block> which is
288 syntactically equivalent to a single <strong|statement>.<\footnote>
289 K&R 2nd Ed., Sec. 3.1 \PStatements and Blocks\Q.
292 <item*|<label|term struct>struct>(short:
293 <hlink|struct|https://en.wikipedia.org/wiki/struct_(C_programming_language)>)
294 a <hlink|composite data type|https://en.wikipedia.org/wiki/Composite_data_type>
295 that defines a physically grouped list of variables under one name in a
296 block of memory, allowing the different variables to be accessed via a
297 single <hlink|pointer|https://en.wikipedia.org/wiki/Pointer_(computer_programming)>
298 or by the struct declared name which returns the same address.
300 <label|term structure_assignment><item*|structure assignment>The act of
301 <hlink|assigning|https://en.wikipedia.org/wiki/Assignment_(computer_science)>
302 a <hlink|struct|https://en.wikipedia.org/wiki/struct_(C_programming_language)>
303 to another struct. (?) (<hlink|example|https://stackoverflow.com/a/2302359/10850071>)
305 <item*|<label|term text_stream>text stream>A sequence of characters
306 divided into lines; each line consists of zero or more characters
307 followed by a newline character. (See K&R 2nd Ed. Section 1.5 \PCharacter
310 <label|term_type><item*|type>A way of differentiating data stored for use
311 in a program. Some types include <cpp|int> (integers), <cpp|char>
312 (single-byte characters), <cpp|short> (a short integer), <cpp|long> (a
313 long integer), <cpp|double> (a double-precision floating point number).
314 </description-compact>
320 <subsection|Character Input and Output>
323 <item*|<cpp|getchar()><label|func getchar>>Read one character at a time
324 from the input buffer. Returns as <cpp|int> a <em|character
325 constant>.<\footnote>
326 <name|ASCII> characters have constants in the range <math|0-127>. UTF-8
327 characters return multiple constants (e.g. \<#B0\> returns <cpp|194
328 176>). See <hlinkv|https://www.smashingmagazine.com/2012/06/all-about-unicode-utf8-character-sets/>.
329 A strategy for reading the multiple bytes of a UTF-8 character is here:
330 <hlinkv|https://stackoverflow.com/a/34240796/>.
333 <item*|<cpp|for()>>A generalization of <cpp|while()>. Takes three
337 <item>Local statement to run before loop (e.g. to initialize a counting
340 <item>Local statement that, if evaluated as true, permits running of
341 next iteration of loop.
343 <item>Local statement to run after loop (e.g. to increment a counting
347 <item*|<cpp|putchar(int arg1)><label|func putchar>>Write one integer
348 character (e.g. <cpp|arg1>) at a time.
350 <item*|<cpp|printf()>>Used for printing formatted text to console.
352 Character codes include:
354 <\description-aligned>
355 <item*|<cpp|%c>>Used to display a character by its <cpp|int>.
357 <item*|<cpp|%d>>Used with <cpp|int> (i.e. 16-bit integers; max value of
358 <math|2<rsup|16>=32\<space\>767>).
360 <item*|<cpp|%ld>>Used with <cpp|long> (i.e. at least 32-bit
361 integers).<\footnote>
362 K&R 2nd Ed., Sec. 1.5 \PThe conversion specification <cpp|%ld> tells
363 <cpp|printf> that the corresponding argument is a <cpp|long>
367 <item*|<cpp|%f>>Used with <cpp|float> and <cpp|double> (double
368 precision <cpp|float>).
369 </description-aligned>
371 For printing <name|UTF-8> strings (which are multibyte in contrast to
372 one-byte <name|ASCII> strings), functions from the C standard library
373 <cpp|wchar.h> header file<\footnote>
374 See <hlinkv|https://en.wikibooks.org/wiki/C_Programming/wchar.h>.
375 </footnote> may need to be<\footnote>
376 See <hlinkv|https://linuxprograms.wordpress.com/tag/c-utf-8-handling/>.
377 </footnote> used<\footnote>
378 See <hlinkv|https://stackoverflow.com/questions/56756204/compatibility-of-printf-with-utf-8-encoded-strings>.
379 </footnote> (e.g. <cpp|wprintf()> (?)).
386 <section|Text Editor>
389 <item><name|Emacs> - GNU text editor. See
390 <hlinkv|https://www.gnu.org/software/emacs/>.
392 <item><name|Vim> - text editor See <hlinkv|https://www.vim.org/>.
397 (TODO: Insert C language linter here)
404 <associate|preamble|false>
410 <associate|auto-1|<tuple|1|?>>
411 <associate|auto-2|<tuple|1.1|?>>
412 <associate|auto-3|<tuple|1.2|?>>
413 <associate|auto-4|<tuple|1.2.1|?>>
414 <associate|auto-5|<tuple|2|?>>
415 <associate|auto-6|<tuple|2.1|?>>
416 <associate|auto-7|<tuple|2.2|?>>
417 <associate|footnote-1.1.1|<tuple|1.1.1|?>>
418 <associate|footnote-1.1.10|<tuple|1.1.10|?>>
419 <associate|footnote-1.1.11|<tuple|1.1.11|?>>
420 <associate|footnote-1.1.2|<tuple|1.1.2|?>>
421 <associate|footnote-1.1.3|<tuple|1.1.3|?>>
422 <associate|footnote-1.1.4|<tuple|1.1.4|?>>
423 <associate|footnote-1.1.5|<tuple|1.1.5|?>>
424 <associate|footnote-1.1.6|<tuple|1.1.6|?>>
425 <associate|footnote-1.1.7|<tuple|1.1.7|?>>
426 <associate|footnote-1.1.8|<tuple|1.1.8|?>>
427 <associate|footnote-1.1.9|<tuple|1.1.9|?>>
428 <associate|footnote-1.2.1|<tuple|1.2.1|?>>
429 <associate|footnote-1.2.2|<tuple|1.2.2|?>>
430 <associate|footnote-1.2.3|<tuple|1.2.3|?>>
431 <associate|footnote-1.2.4|<tuple|1.2.4|?>>
432 <associate|footnote-1.2.5|<tuple|1.2.5|?>>
433 <associate|footnr-1.1.1|<tuple|1.1.1|?>>
434 <associate|footnr-1.1.10|<tuple|1.1.10|?>>
435 <associate|footnr-1.1.11|<tuple|1.1.11|?>>
436 <associate|footnr-1.1.2|<tuple|1.1.2|?>>
437 <associate|footnr-1.1.3|<tuple|1.1.3|?>>
438 <associate|footnr-1.1.4|<tuple|1.1.4|?>>
439 <associate|footnr-1.1.5|<tuple|1.1.5|?>>
440 <associate|footnr-1.1.6|<tuple|1.1.6|?>>
441 <associate|footnr-1.1.7|<tuple|1.1.7|?>>
442 <associate|footnr-1.1.8|<tuple|1.1.8|?>>
443 <associate|footnr-1.1.9|<tuple|1.1.9|?>>
444 <associate|footnr-1.2.1|<tuple|1.2.1|?>>
445 <associate|footnr-1.2.2|<tuple|1.2.2|?>>
446 <associate|footnr-1.2.3|<tuple|1.2.3|?>>
447 <associate|footnr-1.2.4|<tuple|1.2.4|?>>
448 <associate|footnr-1.2.5|<tuple|1.2.5|?>>
449 <associate|func getchar|<tuple|1.2.1|?>>
450 <associate|func putchar|<tuple|3|?>>
451 <associate|ref includehelp-oct-hex|<tuple|1.1.3|?>>
452 <associate|term declaration|<tuple|call|?>>
453 <associate|term definition|<tuple|1.1.1|?>>
454 <associate|term enumeration|<tuple|linter|?>>
455 <associate|term escape_sequence|<tuple|enumeration|?>>
456 <associate|term garbage_collection|<tuple|1.1.10|?>>
457 <associate|term heap|<tuple|garbage collection|?>>
458 <associate|term machine-independent|<tuple|<label|term heap>heap|?>>
459 <associate|term operand|<tuple|<label|term
460 machine-independent>machine-independent|?>>
461 <associate|term operator|<tuple|<label|term operand>operand|?>>
462 <associate|term stack|<tuple|parameter|?>>
463 <associate|term struct|<tuple|1.1.11|?>>
464 <associate|term structure_assignment|<tuple|<label|term struct>struct|?>>
465 <associate|term text_stream|<tuple|structure assignment|?>>
466 <associate|term_argument|<tuple|1.1|?>>
467 <associate|term_call|<tuple|assignment|?>>
468 <associate|term_expression|<tuple|1.1.4|?>>
469 <associate|term_function|<tuple|1.1.8|?>>
470 <associate|term_function_call|<tuple|function|?>>
471 <associate|term_function_prototype|<tuple|function call|?>>
472 <associate|term_linter|<tuple|1.1.2|?>>
473 <associate|term_parameter|<tuple|<label|term operator>operator|?>>
474 <associate|term_statement|<tuple|<label|term stack>stack|?>>
475 <associate|term_type|<tuple|<label|term text_stream>text stream|?>>
482 <vspace*|1fn><with|font-series|<quote|bold>|math-font-series|<quote|bold>|1<space|2spc>Definitions>
483 <datoms|<macro|x|<repeat|<arg|x>|<with|font-series|medium|<with|font-size|1|<space|0.2fn>.<space|0.2fn>>>>>|<htab|5mm>>
484 <no-break><pageref|auto-1><vspace|0.5fn>
486 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>>
487 <no-break><pageref|auto-2>
489 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>>
490 <no-break><pageref|auto-3>
492 <with|par-left|<quote|1tab>|1.2.1<space|2spc>Character Input and Output
493 <datoms|<macro|x|<repeat|<arg|x>|<with|font-series|medium|<with|font-size|1|<space|0.2fn>.<space|0.2fn>>>>>|<htab|5mm>>
494 <no-break><pageref|auto-4>>
496 <vspace*|1fn><with|font-series|<quote|bold>|math-font-series|<quote|bold>|2<space|2spc>Utilities>
497 <datoms|<macro|x|<repeat|<arg|x>|<with|font-series|medium|<with|font-size|1|<space|0.2fn>.<space|0.2fn>>>>>|<htab|5mm>>
498 <no-break><pageref|auto-5><vspace|0.5fn>
500 2.1<space|2spc>Text Editor <datoms|<macro|x|<repeat|<arg|x>|<with|font-series|medium|<with|font-size|1|<space|0.2fn>.<space|0.2fn>>>>>|<htab|5mm>>
501 <no-break><pageref|auto-6>
503 2.2<space|2spc>Linter <datoms|<macro|x|<repeat|<arg|x>|<with|font-series|medium|<with|font-size|1|<space|0.2fn>.<space|0.2fn>>>>>|<htab|5mm>>
504 <no-break><pageref|auto-7>