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 <item*|call>The act of running (or \Pinvoking\Q) a <strong|function>. See
61 <item*|declaration<label|term 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 <item*|definition<label|term 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 <item*|delinter><label|term_delinter> A source code analysis program
78 designed to detect common syntactic errors.
80 <item*|enumeration<label|term 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 <item*|escape sequence<label|term 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>>).
131 </description-aligned>
133 <label|term_expression><item*|expression> A sequence of
134 <strong|operators> and <strong|operands> that specify a computation. When
135 evaluated, an expression may perform useful side effects (e.g.
136 <cpp|printf("%d", 4)> sends the character <cpp|4> to \ the standard
137 output stream)<\footnote>
138 See <hlinkv|https://en.cppreference.com/w/c/language/expressions>.
141 Arrangements of expressions may include<\footnote>
142 See <hlinkv|https://www.educative.io/answers/what-are-expressions-in-c>.
146 <item*|Constant>A value with no operator is used<\footnote>
147 See <hlinkv|https://www.cs.miami.edu/home/burt/learning/Math120.1/Notes/exp-syn.html>.
148 </footnote>. (e.g. the \P<cpp|0>\Q in <cpp|return 0;>)
150 <item*|Variable identifier>A variable evaluated earlier. (e.g. the 2nd
151 \P<cpp|k>\Q in <hgroup|<cpp|k = 1; return k;>>)
153 <item*|Infix expression>Operator is used between operands. (e.g. <cpp|a
156 <item*|Postfix expression>Operator is used after the operands. (e.g.
159 <item*|Prefix expression>Operator is used before the operands. (e.g.
162 <item*|Unary expression>There is one operator and one operand. (e.g.
165 <item*|Binary expression>There is one operator and two operands. (e.g.
169 Types of expressions may include:
172 <item*|Arithmetic expression>Consists of arithmetic operators (<cpp|+,
173 -, *, and />) and computes values of <cpp|int, float, or double> type.
175 <item*|Relational expression>Usually uses comparison operators
176 (<cpp|\<gtr\>, \<less\>, \<gtr\>=, \<less\>=, ===, and !==>) and
177 computers answer in the <cpp|bool> type (i.e. true \P<cpp|1>\Q or false
180 <item*|Logical expression>Consists of logical operators (<cpp|&&, \|\|,
181 and !>) and combines relational expressions to compute answers in the
184 <item*|Conditional expression>Consists of statements that return
185 <cpp|true> if the condition is met or <cpp|false> otherwise.
187 <item*|Pointer expression>May consist of an ampersand (<cpp|&>)
188 operator and returns <cpp|address> values.
190 <item*|Bitwise expression>Consists of bitwise operators
191 (<cpp|\<gtr\>\<gtr\>, \<less\>\<less\>, ~, &, \|, and ^>) and performs
192 operations at the bit level.
194 <item*|Constant expression>Involves only constants such that the
195 expression may be evaluated during compilation rather than
197 K&R 2nd Ed., Sec. 2.3 \PConstants\Q.
201 <label|term_function><item*|function>A group of statements that perform a
202 task. Is defined using a function <strong|definition> that has a
203 parenthesized list of <strong|declarations> called <strong|parameters>
204 (e.g. variables for accepting values named <strong|arguments> as input
205 when the <strong|function> is called). A function definition has the
209 return-type<space|1em>function-name(parameter declarations, if any) {
211 <space|1em>declarations
213 <space|1em>statements
218 <item*|function call>An expression containing the <strong|function> name
219 followed by the function call operator \P<cpp|()>\Q.
221 <label|term garbage_collection><item*|garbage collection>The process of
222 freeing memory allocated by a program but which is no longer referenced.
223 Usually incurs a significant <hlink|speed
224 penalty|https://en.wikipedia.org/wiki/Overhead_(computing)>.
225 (<hlink|Wikipedia|https://en.wikipedia.org/wiki/Garbage_collection_(computer_science)>).
226 The <name|C> Language does not provide garbage collection by default.
228 <item*|<label|term heap>heap>A large pool of memory that can be used
229 dynamically \U it is also known as the \Pfree store\Q. This is memory
230 that is not automatically managed \U you have to explicitly allocate
231 (using functions such as malloc), and deallocate (e.g. free) the memory.
232 Failure to free the memory when you are finished with it will result in
233 what is known as a memory leak. Is the diametrical opposite of the stack
234 (which, by contrast, is limited not by physical memory but by a
235 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/>).
237 <item*|<label|term machine-independent>machine-independent>A property of
238 code that does not have to be modified in order to run on a different
239 hardware architecture. (e.g. \PC is called a portable language because
240 [code written in C] will run on any machine which supports C, without
241 modifying a single line of code.\Q; <hlink|link|https://www.log2base2.com/C/basic/introduction-to-c-language.html>).
243 <item*|<label|term operand>operand>A quantity to which an operator is
244 applied. (e.g. in the <name|C> math expression <code*|7 - 4 = 3>,
245 <code*|7> is the first operand and <code*|4> is the second operand.)
247 <item*|<label|term operator>operator>A special type of function with
248 limited numbers of parameters (e.g. 1 to 2) and syntax often requiring a
249 set of characters different from those normally use for naming variables
250 (e.g. the <code*|+> character in <code*|myVar = 1 + 2>, the <code*|&&> in
251 <code*|a && b>, or the <code*|++> in <code*|i++>.).
253 <label|term_parameter><item*|parameter>Generally, a variable named in the
254 parenthesized list in a <strong|function> definition. Also known as a
255 \Pformal argument\Q as opposed to an \Pactual argument\Q (e.g.
256 <strong|argument>). See <em|argument>.
258 <item*|<label|term stack>stack>A region of memory for global variable
259 storage and is permanent for the entire run of the program. Stack size is
260 limited not by physical memory availability but by the CPU. Lifetime of
261 local variables declared within the stack is enforced by the Last-In,
262 First-Out nature of the stack; when a function returns a value, all stack
263 memory allocated by declarations within the function is automatically
264 freed. (See <hlink|craftofcoding.wordpress.com|https://craftofcoding.wordpress.com/2015/12/07/memory-in-c-the-stack-the-heap-and-static/>)
266 <label|term_statement><item*|statement>An <strong|expression> when it is
267 followed by a semicolon. May be grouped together using braces (i.e.
268 \P<cpp|{ }>\Q) to form a <em|compound statement> or <em|block> which is
269 syntactically equivalent to a single <strong|statement>.<\footnote>
270 K&R 2nd Ed., Sec. 3.1 \PStatements and Blocks\Q.
273 <item*|<label|term struct>struct>(short:
274 <hlink|struct|https://en.wikipedia.org/wiki/struct_(C_programming_language)>)
275 a <hlink|composite data type|https://en.wikipedia.org/wiki/Composite_data_type>
276 that defines a physically grouped list of variables under one name in a
277 block of memory, allowing the different variables to be accessed via a
278 single <hlink|pointer|https://en.wikipedia.org/wiki/Pointer_(computer_programming)>
279 or by the struct declared name which returns the same address.
281 <label|term structure_assignment><item*|structure assignment>The act of
282 <hlink|assigning|https://en.wikipedia.org/wiki/Assignment_(computer_science)>
283 a <hlink|struct|https://en.wikipedia.org/wiki/struct_(C_programming_language)>
284 to another struct. (?) (<hlink|example|https://stackoverflow.com/a/2302359/10850071>)
286 <item*|<label|term text_stream>text stream>A sequence of characters
287 divided into lines; each line consists of zero or more characters
288 followed by a newline character. (See K&R 2nd Ed. Section 1.5 \PCharacter
291 <item*|type>A way of differentiating data stored for use in a program.
292 Some types include <cpp|int> (integers), <cpp|char> (single-byte
293 characters), <cpp|short> (a short integer), <cpp|long> (a long integer),
294 <cpp|double> (a double-precision floating point number).
295 </description-compact>
301 <subsection|Character Input and Output>
304 <item*|<cpp|getchar()><label|func getchar>>Read one character at a time
305 from the input buffer. Returns as <cpp|int> a <em|character
306 constant>.<\footnote>
307 <name|ASCII> characters have constants in the range <math|0-127>. UTF-8
308 characters return multiple constants (e.g. \<#B0\> returns <cpp|194
309 176>). See <hlinkv|https://www.smashingmagazine.com/2012/06/all-about-unicode-utf8-character-sets/>.
310 A strategy for reading the multiple bytes of a UTF-8 character is here:
311 <hlinkv|https://stackoverflow.com/a/34240796/>.
314 <item*|<cpp|for()>>A generalization of <cpp|while()>. Takes three
318 <item>Local statement to run before loop (e.g. to initialize a counting
321 <item>Local statement that, if evaluated as true, permits running of
322 next iteration of loop.
324 <item>Local statement to run after loop (e.g. to increment a counting
328 <item*|<cpp|putchar(int arg1)><label|func putchar>>Write one integer
329 character (e.g. <cpp|arg1>) at a time.
331 <item*|<cpp|printf()>>Used for printing formatted text to console.
333 Character codes include:
335 <\description-aligned>
336 <item*|<cpp|%c>>Used to display a character by its <cpp|int>.
338 <item*|<cpp|%d>>Used with <cpp|int> (i.e. 16-bit integers; max value of
339 <math|2<rsup|16>=32\<space\>767>).
341 <item*|<cpp|%ld>>Used with <cpp|long> (i.e. at least 32-bit
342 integers).<\footnote>
343 K&R 2nd Ed., Sec. 1.5 \PThe conversion specification <cpp|%ld> tells
344 <cpp|printf> that the corresponding argument is a <cpp|long>
348 <item*|<cpp|%f>>Used with <cpp|float> and <cpp|double> (double
349 precision <cpp|float>).
350 </description-aligned>
352 For printing <name|UTF-8> strings (which are multibyte in contrast to
353 one-byte <name|ASCII> strings), functions from the C standard library
354 <cpp|wchar.h> header file<\footnote>
355 See <hlinkv|https://en.wikibooks.org/wiki/C_Programming/wchar.h>.
356 </footnote> may need to be<\footnote>
357 See <hlinkv|https://linuxprograms.wordpress.com/tag/c-utf-8-handling/>.
358 </footnote> used<\footnote>
359 See <hlinkv|https://stackoverflow.com/questions/56756204/compatibility-of-printf-with-utf-8-encoded-strings>.
360 </footnote> (e.g. <cpp|wprintf()> (?)).
367 <section|Text Editor>
370 <item><name|Emacs> - GNU text editor. See
371 <hlinkv|https://www.gnu.org/software/emacs/>.
373 <item><name|Vim> - text editor See <hlinkv|https://www.vim.org/>.
378 (TODO: Insert C language linter here)
385 <associate|preamble|false>
391 <associate|auto-1|<tuple|1|?>>
392 <associate|auto-2|<tuple|1.1|?>>
393 <associate|auto-3|<tuple|1.2|?>>
394 <associate|auto-4|<tuple|1.2.1|?>>
395 <associate|auto-5|<tuple|2|?>>
396 <associate|auto-6|<tuple|2.1|?>>
397 <associate|auto-7|<tuple|2.2|?>>
398 <associate|footnote-1.1.1|<tuple|1.1.1|?>>
399 <associate|footnote-1.1.2|<tuple|1.1.2|?>>
400 <associate|footnote-1.1.3|<tuple|1.1.3|?>>
401 <associate|footnote-1.1.4|<tuple|1.1.4|?>>
402 <associate|footnote-1.1.5|<tuple|1.1.5|?>>
403 <associate|footnote-1.1.6|<tuple|1.1.6|?>>
404 <associate|footnote-1.1.7|<tuple|1.1.7|?>>
405 <associate|footnote-1.1.8|<tuple|1.1.8|?>>
406 <associate|footnote-1.2.1|<tuple|1.2.1|?>>
407 <associate|footnote-1.2.2|<tuple|1.2.2|?>>
408 <associate|footnote-1.2.3|<tuple|1.2.3|?>>
409 <associate|footnote-1.2.4|<tuple|1.2.4|?>>
410 <associate|footnote-1.2.5|<tuple|1.2.5|?>>
411 <associate|footnr-1.1.1|<tuple|1.1.1|?>>
412 <associate|footnr-1.1.2|<tuple|1.1.2|?>>
413 <associate|footnr-1.1.3|<tuple|1.1.3|?>>
414 <associate|footnr-1.1.4|<tuple|1.1.4|?>>
415 <associate|footnr-1.1.5|<tuple|1.1.5|?>>
416 <associate|footnr-1.1.6|<tuple|1.1.6|?>>
417 <associate|footnr-1.1.7|<tuple|1.1.7|?>>
418 <associate|footnr-1.1.8|<tuple|1.1.8|?>>
419 <associate|footnr-1.2.1|<tuple|1.2.1|?>>
420 <associate|footnr-1.2.2|<tuple|1.2.2|?>>
421 <associate|footnr-1.2.3|<tuple|1.2.3|?>>
422 <associate|footnr-1.2.4|<tuple|1.2.4|?>>
423 <associate|footnr-1.2.5|<tuple|1.2.5|?>>
424 <associate|func getchar|<tuple|1.2.1|?>>
425 <associate|func putchar|<tuple|3|?>>
426 <associate|ref includehelp-oct-hex|<tuple|1.1.3|?>>
427 <associate|term declaration|<tuple|call|?>>
428 <associate|term definition|<tuple|1.1.1|?>>
429 <associate|term enumeration|<tuple|delinter|?>>
430 <associate|term escape_sequence|<tuple|enumeration<label|term
432 <associate|term garbage_collection|<tuple|function call|?>>
433 <associate|term heap|<tuple|garbage collection|?>>
434 <associate|term machine-independent|<tuple|<label|term heap>heap|?>>
435 <associate|term operand|<tuple|<label|term
436 machine-independent>machine-independent|?>>
437 <associate|term operator|<tuple|<label|term operand>operand|?>>
438 <associate|term stack|<tuple|parameter|?>>
439 <associate|term struct|<tuple|1.1.8|?>>
440 <associate|term structure_assignment|<tuple|<label|term struct>struct|?>>
441 <associate|term text_stream|<tuple|structure assignment|?>>
442 <associate|term_argument|<tuple|1.1|?>>
443 <associate|term_delinter|<tuple|delinter|?>>
444 <associate|term_expression|<tuple|<with|mode|<quote|prog>|prog-language|<quote|cpp>|font-family|<quote|rm>|\\x><with|font-shape|<quote|italic>|hh>|?>>
445 <associate|term_function|<tuple|1.1.7|?>>
446 <associate|term_parameter|<tuple|<label|term operator>operator|?>>
447 <associate|term_statement|<tuple|<label|term stack>stack|?>>
448 <associate|term_variable|<tuple|<label|term text_stream>text stream|?>>
455 <vspace*|1fn><with|font-series|<quote|bold>|math-font-series|<quote|bold>|1<space|2spc>Definitions>
456 <datoms|<macro|x|<repeat|<arg|x>|<with|font-series|medium|<with|font-size|1|<space|0.2fn>.<space|0.2fn>>>>>|<htab|5mm>>
457 <no-break><pageref|auto-1><vspace|0.5fn>
459 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>>
460 <no-break><pageref|auto-2>
462 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>>
463 <no-break><pageref|auto-3>
465 <with|par-left|<quote|1tab>|1.2.1<space|2spc>Character Input and Output
466 <datoms|<macro|x|<repeat|<arg|x>|<with|font-series|medium|<with|font-size|1|<space|0.2fn>.<space|0.2fn>>>>>|<htab|5mm>>
467 <no-break><pageref|auto-4>>
469 <vspace*|1fn><with|font-series|<quote|bold>|math-font-series|<quote|bold>|2<space|2spc>Utilities>
470 <datoms|<macro|x|<repeat|<arg|x>|<with|font-series|medium|<with|font-size|1|<space|0.2fn>.<space|0.2fn>>>>>|<htab|5mm>>
471 <no-break><pageref|auto-5><vspace|0.5fn>
473 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>>
474 <no-break><pageref|auto-6>
476 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>>
477 <no-break><pageref|auto-7>