From c3ca1f107dd18400fc2720469e938f3f16889e3e Mon Sep 17 00:00:00 2001 From: Joshua Potter Date: Wed, 27 Nov 2024 07:43:44 -0700 Subject: [PATCH] Intervals and reorganized C files. --- .../plugins/obsidian-to-anki-plugin/data.json | 8 +- .../_journal/{2024-11-26.md => 2024-11-27.md} | 2 +- notes/_journal/2024-11/2024-11-26.md | 11 + notes/c17/alignment.md | 2 +- notes/c17/declarations.md | 491 ------------- notes/c17/functions.md | 608 ++++++++++++++++ notes/c17/pointers.md | 599 +++++++++++++++ notes/c17/types/derived.md | 689 +----------------- notes/calculus/images/postage-function.png | Bin 0 -> 10608 bytes notes/calculus/intervals.md | 232 ++++++ notes/set/cardinality.md | 2 +- 11 files changed, 1460 insertions(+), 1184 deletions(-) rename notes/_journal/{2024-11-26.md => 2024-11-27.md} (62%) create mode 100644 notes/_journal/2024-11/2024-11-26.md create mode 100644 notes/c17/functions.md create mode 100644 notes/c17/pointers.md create mode 100644 notes/calculus/images/postage-function.png create mode 100644 notes/calculus/intervals.md diff --git a/notes/.obsidian/plugins/obsidian-to-anki-plugin/data.json b/notes/.obsidian/plugins/obsidian-to-anki-plugin/data.json index a88ecc0..c91b51d 100644 --- a/notes/.obsidian/plugins/obsidian-to-anki-plugin/data.json +++ b/notes/.obsidian/plugins/obsidian-to-anki-plugin/data.json @@ -221,7 +221,8 @@ "arg-build-area.png", "stack-frame.png", "buffer-overflow.png", - "infinite-cartesian-product.png" + "infinite-cartesian-product.png", + "postage-function.png" ], "File Hashes": { "algorithms/index.md": "3ac071354e55242919cc574eb43de6f8", @@ -802,7 +803,7 @@ "c17/types/enumerated.md": "e1f70a30677c776b7b44ac3e0ff4e76d", "c17/types/derived.md": "74c608d72b25794bc3887f58f001bab2", "c17/types/basic.md": "5064e21e683c0218890058882e06b6f3", - "c17/types/index.md": "14b651bcfc8b2d62ffd200a74a9a2a6b", + "c17/types/index.md": "ae2ebd695b4eeadbabf28c814ce3a052", "_journal/2024-08-25.md": "e73a8edbd027d0f1a39289540eb512f2", "_journal/2024-08/2024-08-24.md": "563fad24740e44734a87d7c3ec46cec4", "algebra/abs-val.md": "a47bc08db62304eb526d15ede3e300cf", @@ -959,7 +960,8 @@ "_journal/2024-11-25.md": "1ec17a8473fa9c4779090ecbd22d70ef", "_journal/2024-11/2024-11-24.md": "894b021e6335d4e6947448c8d362c083", "_journal/2024-11-26.md": "29bc0b54d23034b9108e567a1d5fa8ac", - "_journal/2024-11/2024-11-25.md": "1ec17a8473fa9c4779090ecbd22d70ef" + "_journal/2024-11/2024-11-25.md": "1ec17a8473fa9c4779090ecbd22d70ef", + "calculus/intervals.md": "3c2f6803bf7f89a626b76c464bd715e1" }, "fields_dict": { "Basic": [ diff --git a/notes/_journal/2024-11-26.md b/notes/_journal/2024-11-27.md similarity index 62% rename from notes/_journal/2024-11-26.md rename to notes/_journal/2024-11-27.md index 4893ed0..90d406b 100644 --- a/notes/_journal/2024-11-26.md +++ b/notes/_journal/2024-11-27.md @@ -1,5 +1,5 @@ --- -title: "2024-11-26" +title: "2024-11-27" --- - [ ] Anki Flashcards diff --git a/notes/_journal/2024-11/2024-11-26.md b/notes/_journal/2024-11/2024-11-26.md new file mode 100644 index 0000000..338355c --- /dev/null +++ b/notes/_journal/2024-11/2024-11-26.md @@ -0,0 +1,11 @@ +--- +title: "2024-11-26" +--- + +- [x] Anki Flashcards +- [x] KoL +- [x] OGS +- [ ] Sheet Music (10 min.) +- [ ] Korean (Read 1 Story) + +* Notes on [[intervals]]. \ No newline at end of file diff --git a/notes/c17/alignment.md b/notes/c17/alignment.md index a3534a4..bcf670f 100644 --- a/notes/c17/alignment.md +++ b/notes/c17/alignment.md @@ -9,7 +9,7 @@ tags: ## Overview -For a large class of modern ISAs, storage for basic C datatypes respect **self-alignmnet**. This means `char`s can start on any byte address, `short`s on any even address, 4-byte `int`s and `float`s must start on an address divisible by 4, and `double`s must start on an address divisible by 8. Likewise pointers are also self-aligned. +For a large class of modern ISAs, storage for basic C datatypes respect **self-alignment**. This means `char`s can start on any byte address, `short`s on any even address, 4-byte `int`s and `float`s must start on an address divisible by 4, and `double`s must start on an address divisible by 8. Likewise pointers are also self-aligned. Wasted space introduced solely for alignment purposes is referred to as **slop**. diff --git a/notes/c17/declarations.md b/notes/c17/declarations.md index 527bac8..b44006e 100644 --- a/notes/c17/declarations.md +++ b/notes/c17/declarations.md @@ -275,497 +275,6 @@ Reference: Van der Linden, Peter. _Expert C Programming: Deep C Secrets_. Progra END%% -## Prototypes - -A function declaration/definition has two ways of using declarators: **parameter type lists** and **identifier type lists**. To make the distinction clear, consider the following two ways of defining an `add` function: - -```c -int f(int x, int y) { return x + y; } // Paramter type list -int f(x, y) int x; int y; { return x + y } // Identifier type list -``` - -A function **prototype** is a kind of function declaration that specifies the function signature. There are three important points to make note of: - -* Empty identifier lists are interpreted as "the compiler has not been told what this function's arguments are." -* The standard prohibits declaring functions with a non-empty identifier list. -* Empty parameter lists are not allowed. - -Therefore: - -```c -// Uses an empty identifer list. This declares a function `foo` -// that takes an unknown specification of arguments. -void foo(); -// Uses a non-empty identifier list. Compiler error. -void foo(x, y); -// Uses a non-empty identifier list. Compiler error. -void foo(x, y) int x; int y; -// Uses a non-empty identifier list. Definitions allow this. -void foo(x, y) int x; int y; { } -// Uses a non-empty parameter list. This prototypes a function -// `foo` that takes no arguments. -void foo(void); -// Uses a non-empty parameter list. This prototypes and defines -// a function `foo` that takes no arguments. -void foo(void) {} -``` - -Together these points imply a function prototype *must* use a parameter type list. - -%%ANKI -Basic -Which of prototypes or declarations are more general? -Back: Declarations. -Reference: “ISO: Programming Languages - C,” April 12, 2011, [https://port70.net/~nsz/c/c11/n1570.pdf](https://port70.net/~nsz/c/c11/n1570.pdf). - -END%% - -%%ANKI -Basic -What two ways are parameters declared in function declarations and definitions? -Back: Identifier type lists and parameter type lists. -Reference: “ISO: Programming Languages - C,” April 12, 2011, [https://port70.net/~nsz/c/c11/n1570.pdf](https://port70.net/~nsz/c/c11/n1570.pdf). - -END%% - -%%ANKI -Basic -Which of identifier type lists and/or parameter type lists considered obsolete? -Back: Identifier type lists. -Reference: “ISO: Programming Languages - C,” April 12, 2011, [https://port70.net/~nsz/c/c11/n1570.pdf](https://port70.net/~nsz/c/c11/n1570.pdf). - -END%% - -%%ANKI -Basic -Define an addition function using identifier type lists. -Back: -```c -int add(x, y) int x; int y; { return x + y; } -``` -Reference: “ISO: Programming Languages - C,” April 12, 2011, [https://port70.net/~nsz/c/c11/n1570.pdf](https://port70.net/~nsz/c/c11/n1570.pdf). - -END%% - -%%ANKI -Basic -Define an addition function using parameter type lists. -Back: -```c -int add(int x, int y) { return x + y; } -``` -Reference: “ISO: Programming Languages - C,” April 12, 2011, [https://port70.net/~nsz/c/c11/n1570.pdf](https://port70.net/~nsz/c/c11/n1570.pdf). - -END%% - -%%ANKI -Basic -Is the following a prototype or a declaration? -```c -void foo(); -``` -Back: A declaration. -Reference: “ISO: Programming Languages - C,” April 12, 2011, [https://port70.net/~nsz/c/c11/n1570.pdf](https://port70.net/~nsz/c/c11/n1570.pdf). - -END%% - -%%ANKI -Basic -What compilation error does the following raise? -```c -void foo(); -``` -Back: N/A. -Reference: “ISO: Programming Languages - C,” April 12, 2011, [https://port70.net/~nsz/c/c11/n1570.pdf](https://port70.net/~nsz/c/c11/n1570.pdf). - -END%% - -%%ANKI -Basic -What compilation error does the following raise? -```c -void foo(x, y); -``` -Back: A function declaration cannot have a non-empty identifier list. -Reference: “ISO: Programming Languages - C,” April 12, 2011, [https://port70.net/~nsz/c/c11/n1570.pdf](https://port70.net/~nsz/c/c11/n1570.pdf). - -END%% - -%%ANKI -Basic -What compilation error does the following raise? -```c -void foo(x, y) int x; int y; -``` -Back: A function declaration cannot have a non-empty identifier list. -Reference: “ISO: Programming Languages - C,” April 12, 2011, [https://port70.net/~nsz/c/c11/n1570.pdf](https://port70.net/~nsz/c/c11/n1570.pdf). - -END%% - -%%ANKI -Basic -What compilation error does the following raise? -```c -void foo(x, y) int x; int y; {} -``` -Back: N/A. -Reference: “ISO: Programming Languages - C,” April 12, 2011, [https://port70.net/~nsz/c/c11/n1570.pdf](https://port70.net/~nsz/c/c11/n1570.pdf). - -END%% - -%%ANKI -Basic -What function prototype is declared in the following? -```c -void foo(x, y) int x; int y; {} -``` -Back: N/A. No prototype has been declared. -Reference: “ISO: Programming Languages - C,” April 12, 2011, [https://port70.net/~nsz/c/c11/n1570.pdf](https://port70.net/~nsz/c/c11/n1570.pdf). - -END%% - -%%ANKI -Basic -What compilation error does the following raise? -```c -void foo(); - -int main(void) { foo(1); } -``` -Back: N/A. -Reference: “ISO: Programming Languages - C,” April 12, 2011, [https://port70.net/~nsz/c/c11/n1570.pdf](https://port70.net/~nsz/c/c11/n1570.pdf). - -END%% - -%%ANKI -Basic -Is the following a prototype or a declaration? -```c -void f(void); -``` -Back: A prototype. -Reference: “ISO: Programming Languages - C,” April 12, 2011, [https://port70.net/~nsz/c/c11/n1570.pdf](https://port70.net/~nsz/c/c11/n1570.pdf). - -END%% - -%%ANKI -Basic -What compilation error does the following raise? -```c -void foo(void); -``` -Back: N/A. -Reference: “ISO: Programming Languages - C,” April 12, 2011, [https://port70.net/~nsz/c/c11/n1570.pdf](https://port70.net/~nsz/c/c11/n1570.pdf). - -END%% - -%%ANKI -Basic -What compilation error does the following raise? -```c -void foo(void); - -int main(void) { foo(1); } -``` -Back: Too many arguments to function call `foo`. -Reference: “ISO: Programming Languages - C,” April 12, 2011, [https://port70.net/~nsz/c/c11/n1570.pdf](https://port70.net/~nsz/c/c11/n1570.pdf). - -END%% - -%%ANKI -Basic -What function prototype is declared in the following? -```c -void foo(int x, int y); -``` -Back: `void foo(int, int)` -Reference: “ISO: Programming Languages - C,” April 12, 2011, [https://port70.net/~nsz/c/c11/n1570.pdf](https://port70.net/~nsz/c/c11/n1570.pdf). - -END%% - -%%ANKI -Basic -What function prototype is declared in the following? -```c -void foo(int x, int y) {} -``` -Back: `void foo(int, int)` -Reference: “ISO: Programming Languages - C,” April 12, 2011, [https://port70.net/~nsz/c/c11/n1570.pdf](https://port70.net/~nsz/c/c11/n1570.pdf). - -END%% - -%%ANKI -Basic -How many arguments does the following declaration specify? -```c -void foo(); -``` -Back: Some number unknown to the compiler. -Reference: “ISO: Programming Languages - C,” April 12, 2011, [https://port70.net/~nsz/c/c11/n1570.pdf](https://port70.net/~nsz/c/c11/n1570.pdf). - -END%% - -%%ANKI -Basic -How many arguments does the following declaration specify? -```c -void foo(void); -``` -Back: Zero. -Reference: “ISO: Programming Languages - C,” April 12, 2011, [https://port70.net/~nsz/c/c11/n1570.pdf](https://port70.net/~nsz/c/c11/n1570.pdf). - -END%% - -%%ANKI -Basic -Why might the following snippet raise a compilation error? -```c -int foo(); -int foo(int a); -``` -Back: N/A. It likely wouldn't. -Reference: “ISO: Programming Languages - C,” April 12, 2011, [https://port70.net/~nsz/c/c11/n1570.pdf](https://port70.net/~nsz/c/c11/n1570.pdf). - -END%% - -%%ANKI -Basic -*Why* might the following snippet raise a compilation error? -```c -int foo(); -int foo(float a); -``` -Back: Conflicting types. The first `foo` declares any `float` passed to it default promotes to a `double`. -Reference: “ISO: Programming Languages - C,” April 12, 2011, [https://port70.net/~nsz/c/c11/n1570.pdf](https://port70.net/~nsz/c/c11/n1570.pdf). - -END%% - -%%ANKI -Basic -*Why* might the following snippet raise a compilation error? -```c -int foo(); -int foo(char a); -``` -Back: Conflicting types. The first `foo` declares any `char` passed to it default promotes to an `int`. -Reference: “ISO: Programming Languages - C,” April 12, 2011, [https://port70.net/~nsz/c/c11/n1570.pdf](https://port70.net/~nsz/c/c11/n1570.pdf). - -END%% - -%%ANKI -Basic -*Why* might the following snippet raise a compilation error? -```c -int foo(); -int foo(double a); -``` -Back: N/A. It likely wouldn't. -Reference: “ISO: Programming Languages - C,” April 12, 2011, [https://port70.net/~nsz/c/c11/n1570.pdf](https://port70.net/~nsz/c/c11/n1570.pdf). - -END%% - -### main - -`main` is a special function serving as the entrypoint to C programs. It can have several different prototypes, but the following two are always possible: - -```c -int main(void); -int main(int argc, char* argv[argc+1]); -``` - -The only two return values guaranteed to work on all platform is `EXIT_SUCCESS` and `EXIT_FAILURE`. Reaching the end of `main` is equivalent to a `reutrn` with value `EXIT_SUCCESS`. - -%%ANKI -Basic -Which function serves as the entrypoint of C programs? -Back: `main` -Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). - -END%% - -%%ANKI -Basic -How many valid prototypes of `main` are available? -Back: Indeterminate. Depends on the system. -Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). - -END%% - -%%ANKI -Basic -How many "official" prototypes of `main` are available? -Back: Two. -Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). - -END%% - -%%ANKI -Basic -What are the "official" prototypes of `main`? -Back: -```c -int main(void); -int main(int argc, char* argv[argc + 1]); -``` -Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). - -END%% - -%%ANKI -Basic -What are the "official" prototypes of `main`? -Back: -```c -int main(void); -int main(int argc, char* argv[argc + 1]); -``` -Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). -END%% - -%%ANKI -Basic -What are the only portable values that `main` can return? -Back: `EXIT_SUCCESS` and `EXIT_FAILURE`. -Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). - -END%% - -%%ANKI -Basic -Which library defines `EXIT_SUCCESS`? -Back: `stdlib.h` -Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). - -END%% - -%%ANKI -Basic -Which library defines `EXIT_FAILURE`? -Back: `stdlib.h` -Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). - -END%% - -%%ANKI -Basic -What happens when `main` does not explicitly return a value? -Back: `EXIT_SUCCESS` is implicitly returned. -Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). - -END%% - -%%ANKI -Cloze -Returning {1:`s`} in {1:`main`} is equivalent to invoking function {2:`exit`} with argument {2:`s`}. -Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). - -END%% - -%%ANKI -Basic -Which library declares the following prototype? -```c -noreturn void exit(int) -``` -Back: `stdlib.h` -Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). - -END%% - -%%ANKI -Basic -What does keyword `_Noreturn` indicate? -Back: The associated callee will never return control back to the caller. -Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). - -END%% - -%%ANKI -Basic -What kind of syntactical construct is `_Noreturn`? -Back: A special keyword. -Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). - -END%% - -%%ANKI -Basic -What kind of syntactical construct is `noreturn`? -Back: A macro. -Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). - -END%% - -%%ANKI -Cloze -{1:`_Noreturn`} is a {2:keyword} whereas {2:`noreturn`} is a {1:macro}. -Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). - -END%% - -%%ANKI -Basic -Which library is `noreturn` defined in? -Back: `stdnoreturn.h` -Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). - -END%% - -%%ANKI -Basic -Consider the following prototype. What is the value of `argv[0]`? -```c -int main(int argc, char* argv[argc + 1]); -``` -Back: The name of the program invocation. -Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). - -END%% - -%%ANKI -Basic -Consider the following prototype. What is the value of `argv[argc]`? -```c -int main(int argc, char* argv[argc + 1]); -``` -Back: `0` -Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). - -END%% - -%%ANKI -Basic -Consider the following prototype. What is the value of `argv[1]`? -```c -int main(int argc, char* argv[argc + 1]); -``` -Back: `0` if `argc == 1` else the first argument to the program. -Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). - -END%% - -%%ANKI -Basic -Consider the following prototype. What is the minimum value of `argc`? -```c -int main(int argc, char* argv[argc + 1]); -``` -Back: `1` -Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). - -END%% - -%%ANKI -Basic -Consider the following prototype. What is the minimum length of `argv`? -```c -int main(int argc, char* argv[argc + 1]); -``` -Back: `2` -Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). - -END%% - ## Initializers An **initializer** is an expression that gives an object a value at time of declaration. Only variable-length arrays (VLAs) do not allow for an initializer. The default initializer looks like `{0}`. diff --git a/notes/c17/functions.md b/notes/c17/functions.md new file mode 100644 index 0000000..0d6a005 --- /dev/null +++ b/notes/c17/functions.md @@ -0,0 +1,608 @@ +--- +title: Functions +TARGET DECK: Obsidian::STEM +FILE TAGS: c17::function +tags: + - c17 +--- + +## Overview + +A function `f` without a following opening `(` is converted to a pointer to its start. This is called **function decay**. + +%%ANKI +Basic +What is the effect of function decay? +Back: Evaluation of a function `f` without a following opening `(` is converted to a pointer to its start. +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +%%ANKI +Basic +What name is given to the implicit conversion of a function to a pointer? +Back: Function decay. +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +%%ANKI +Basic +According to Gustedt, what C feature explains why are there no "function values"? +Back: Function-to-pointer decay. +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +%%ANKI +Basic +Why can't functions directly be made arguments to functions? +Back: Because function arguments decay to pointers. +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +%%ANKI +Cloze +{1:Function pointers} are to {2:`(...)`} whereas {2:pointers} are to {1:`[...]`}. +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +%%ANKI +Basic +In what order are decays, dereferences, address ofs, and calls performed in the following? +```c +f(3); +``` +Back: Decay, call. +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +%%ANKI +Basic +In what order are decays, dereferences, address ofs, and calls performed in the following? +```c +(&f)(3); +``` +Back: Address of, call. +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +%%ANKI +Basic +In what order are decays, dereferences, address ofs, and calls performed in the following? +```c +(*f)(3); +``` +Back: Decay, dereference, decay, call. +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +%%ANKI +Basic +In what order are decays, dereferences, address ofs, and calls performed in the following? +```c +(*&f)(3); +``` +Back: Address of, dereference, decay, call. +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +%%ANKI +Basic +In what order are decays, dereferences, address ofs, and calls performed in the following? +```c +(&*f)(3); +``` +Back: Decay, dereference, address of, call. +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +%%ANKI +Cloze +{1:Pointers} refer to {2:arrays} whereas {2:function pointers} refer to {1:functions}. +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +## Prototypes + +A function declaration/definition has two ways of using declarators: **parameter type lists** and **identifier type lists**. To make the distinction clear, consider the following two ways of defining an `add` function: + +```c +int f(int x, int y) { return x + y; } // Paramter type list +int f(x, y) int x; int y; { return x + y } // Identifier type list +``` + +A function **prototype** is a kind of function [[c17/declarations|declaration]] that specifies the function signature. There are three important points to make note of: + +* Empty identifier lists are interpreted as "the compiler has not been told what this function's arguments are." +* The standard prohibits declaring functions with a non-empty identifier list. +* Empty parameter lists are not allowed. + +Therefore: + +```c +// Uses an empty identifer list. This declares a function `foo` +// that takes an unknown specification of arguments. +void foo(); +// Uses a non-empty identifier list. Compiler error. +void foo(x, y); +// Uses a non-empty identifier list. Compiler error. +void foo(x, y) int x; int y; +// Uses a non-empty identifier list. Definitions allow this. +void foo(x, y) int x; int y; { } +// Uses a non-empty parameter list. This prototypes a function +// `foo` that takes no arguments. +void foo(void); +// Uses a non-empty parameter list. This prototypes and defines +// a function `foo` that takes no arguments. +void foo(void) {} +``` + +Together these points imply a function prototype *must* use a parameter type list. + +%%ANKI +Basic +Which of prototypes or declarations are more general? +Back: Declarations. +Reference: “ISO: Programming Languages - C,” April 12, 2011, [https://port70.net/~nsz/c/c11/n1570.pdf](https://port70.net/~nsz/c/c11/n1570.pdf). + +END%% + +%%ANKI +Basic +What two ways are parameters declared in function declarations and definitions? +Back: Identifier type lists and parameter type lists. +Reference: “ISO: Programming Languages - C,” April 12, 2011, [https://port70.net/~nsz/c/c11/n1570.pdf](https://port70.net/~nsz/c/c11/n1570.pdf). + +END%% + +%%ANKI +Basic +Which of identifier type lists and/or parameter type lists considered obsolete? +Back: Identifier type lists. +Reference: “ISO: Programming Languages - C,” April 12, 2011, [https://port70.net/~nsz/c/c11/n1570.pdf](https://port70.net/~nsz/c/c11/n1570.pdf). + +END%% + +%%ANKI +Basic +Define an addition function using identifier type lists. +Back: +```c +int add(x, y) int x; int y; { return x + y; } +``` +Reference: “ISO: Programming Languages - C,” April 12, 2011, [https://port70.net/~nsz/c/c11/n1570.pdf](https://port70.net/~nsz/c/c11/n1570.pdf). + +END%% + +%%ANKI +Basic +Define an addition function using parameter type lists. +Back: +```c +int add(int x, int y) { return x + y; } +``` +Reference: “ISO: Programming Languages - C,” April 12, 2011, [https://port70.net/~nsz/c/c11/n1570.pdf](https://port70.net/~nsz/c/c11/n1570.pdf). + +END%% + +%%ANKI +Basic +Is the following a prototype or a declaration? +```c +void foo(); +``` +Back: A declaration. +Reference: “ISO: Programming Languages - C,” April 12, 2011, [https://port70.net/~nsz/c/c11/n1570.pdf](https://port70.net/~nsz/c/c11/n1570.pdf). + +END%% + +%%ANKI +Basic +What compilation error does the following raise? +```c +void foo(); +``` +Back: N/A. +Reference: “ISO: Programming Languages - C,” April 12, 2011, [https://port70.net/~nsz/c/c11/n1570.pdf](https://port70.net/~nsz/c/c11/n1570.pdf). + +END%% + +%%ANKI +Basic +What compilation error does the following raise? +```c +void foo(x, y); +``` +Back: A function declaration cannot have a non-empty identifier list. +Reference: “ISO: Programming Languages - C,” April 12, 2011, [https://port70.net/~nsz/c/c11/n1570.pdf](https://port70.net/~nsz/c/c11/n1570.pdf). + +END%% + +%%ANKI +Basic +What compilation error does the following raise? +```c +void foo(x, y) int x; int y; +``` +Back: A function declaration cannot have a non-empty identifier list. +Reference: “ISO: Programming Languages - C,” April 12, 2011, [https://port70.net/~nsz/c/c11/n1570.pdf](https://port70.net/~nsz/c/c11/n1570.pdf). + +END%% + +%%ANKI +Basic +What compilation error does the following raise? +```c +void foo(x, y) int x; int y; {} +``` +Back: N/A. +Reference: “ISO: Programming Languages - C,” April 12, 2011, [https://port70.net/~nsz/c/c11/n1570.pdf](https://port70.net/~nsz/c/c11/n1570.pdf). + +END%% + +%%ANKI +Basic +What function prototype is declared in the following? +```c +void foo(x, y) int x; int y; {} +``` +Back: N/A. No prototype has been declared. +Reference: “ISO: Programming Languages - C,” April 12, 2011, [https://port70.net/~nsz/c/c11/n1570.pdf](https://port70.net/~nsz/c/c11/n1570.pdf). + +END%% + +%%ANKI +Basic +What compilation error does the following raise? +```c +void foo(); + +int main(void) { foo(1); } +``` +Back: N/A. +Reference: “ISO: Programming Languages - C,” April 12, 2011, [https://port70.net/~nsz/c/c11/n1570.pdf](https://port70.net/~nsz/c/c11/n1570.pdf). + +END%% + +%%ANKI +Basic +Is the following a prototype or a declaration? +```c +void f(void); +``` +Back: A prototype. +Reference: “ISO: Programming Languages - C,” April 12, 2011, [https://port70.net/~nsz/c/c11/n1570.pdf](https://port70.net/~nsz/c/c11/n1570.pdf). + +END%% + +%%ANKI +Basic +What compilation error does the following raise? +```c +void foo(void); +``` +Back: N/A. +Reference: “ISO: Programming Languages - C,” April 12, 2011, [https://port70.net/~nsz/c/c11/n1570.pdf](https://port70.net/~nsz/c/c11/n1570.pdf). + +END%% + +%%ANKI +Basic +What compilation error does the following raise? +```c +void foo(void); + +int main(void) { foo(1); } +``` +Back: Too many arguments to function call `foo`. +Reference: “ISO: Programming Languages - C,” April 12, 2011, [https://port70.net/~nsz/c/c11/n1570.pdf](https://port70.net/~nsz/c/c11/n1570.pdf). + +END%% + +%%ANKI +Basic +What function prototype is declared in the following? +```c +void foo(int x, int y); +``` +Back: `void foo(int, int)` +Reference: “ISO: Programming Languages - C,” April 12, 2011, [https://port70.net/~nsz/c/c11/n1570.pdf](https://port70.net/~nsz/c/c11/n1570.pdf). + +END%% + +%%ANKI +Basic +What function prototype is declared in the following? +```c +void foo(int x, int y) {} +``` +Back: `void foo(int, int)` +Reference: “ISO: Programming Languages - C,” April 12, 2011, [https://port70.net/~nsz/c/c11/n1570.pdf](https://port70.net/~nsz/c/c11/n1570.pdf). + +END%% + +%%ANKI +Basic +How many arguments does the following declaration specify? +```c +void foo(); +``` +Back: Some number unknown to the compiler. +Reference: “ISO: Programming Languages - C,” April 12, 2011, [https://port70.net/~nsz/c/c11/n1570.pdf](https://port70.net/~nsz/c/c11/n1570.pdf). + +END%% + +%%ANKI +Basic +How many arguments does the following declaration specify? +```c +void foo(void); +``` +Back: Zero. +Reference: “ISO: Programming Languages - C,” April 12, 2011, [https://port70.net/~nsz/c/c11/n1570.pdf](https://port70.net/~nsz/c/c11/n1570.pdf). + +END%% + +%%ANKI +Basic +Why might the following snippet raise a compilation error? +```c +int foo(); +int foo(int a); +``` +Back: N/A. It likely wouldn't. +Reference: “ISO: Programming Languages - C,” April 12, 2011, [https://port70.net/~nsz/c/c11/n1570.pdf](https://port70.net/~nsz/c/c11/n1570.pdf). + +END%% + +%%ANKI +Basic +*Why* might the following snippet raise a compilation error? +```c +int foo(); +int foo(float a); +``` +Back: Conflicting types. The first `foo` declares any `float` passed to it default promotes to a `double`. +Reference: “ISO: Programming Languages - C,” April 12, 2011, [https://port70.net/~nsz/c/c11/n1570.pdf](https://port70.net/~nsz/c/c11/n1570.pdf). + +END%% + +%%ANKI +Basic +*Why* might the following snippet raise a compilation error? +```c +int foo(); +int foo(char a); +``` +Back: Conflicting types. The first `foo` declares any `char` passed to it default promotes to an `int`. +Reference: “ISO: Programming Languages - C,” April 12, 2011, [https://port70.net/~nsz/c/c11/n1570.pdf](https://port70.net/~nsz/c/c11/n1570.pdf). + +END%% + +%%ANKI +Basic +*Why* might the following snippet raise a compilation error? +```c +int foo(); +int foo(double a); +``` +Back: N/A. It likely wouldn't. +Reference: “ISO: Programming Languages - C,” April 12, 2011, [https://port70.net/~nsz/c/c11/n1570.pdf](https://port70.net/~nsz/c/c11/n1570.pdf). + +END%% + +### main + +`main` is a special function serving as the entrypoint to C programs. It can have several different prototypes, but the following two are always possible: + +```c +int main(void); +int main(int argc, char* argv[argc+1]); +``` + +The only two return values guaranteed to work on all platform is `EXIT_SUCCESS` and `EXIT_FAILURE`. Reaching the end of `main` is equivalent to a `reutrn` with value `EXIT_SUCCESS`. + +%%ANKI +Basic +Which function serves as the entrypoint of C programs? +Back: `main` +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +%%ANKI +Basic +How many valid prototypes of `main` are available? +Back: Indeterminate. Depends on the system. +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +%%ANKI +Basic +How many "official" prototypes of `main` are available? +Back: Two. +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +%%ANKI +Basic +What are the "official" prototypes of `main`? +Back: +```c +int main(void); +int main(int argc, char* argv[argc + 1]); +``` +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +%%ANKI +Basic +What are the "official" prototypes of `main`? +Back: +```c +int main(void); +int main(int argc, char* argv[argc + 1]); +``` +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). +END%% + +%%ANKI +Basic +What are the only portable values that `main` can return? +Back: `EXIT_SUCCESS` and `EXIT_FAILURE`. +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +%%ANKI +Basic +Which library defines `EXIT_SUCCESS`? +Back: `stdlib.h` +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +%%ANKI +Basic +Which library defines `EXIT_FAILURE`? +Back: `stdlib.h` +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +%%ANKI +Basic +What happens when `main` does not explicitly return a value? +Back: `EXIT_SUCCESS` is implicitly returned. +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +%%ANKI +Cloze +Returning {1:`s`} in {1:`main`} is equivalent to invoking function {2:`exit`} with argument {2:`s`}. +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +%%ANKI +Basic +Which library declares the following prototype? +```c +noreturn void exit(int) +``` +Back: `stdlib.h` +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +%%ANKI +Basic +What does keyword `_Noreturn` indicate? +Back: The associated callee will never return control back to the caller. +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +%%ANKI +Basic +What kind of syntactical construct is `_Noreturn`? +Back: A special keyword. +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +%%ANKI +Basic +What kind of syntactical construct is `noreturn`? +Back: A macro. +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +%%ANKI +Cloze +{1:`_Noreturn`} is a {2:keyword} whereas {2:`noreturn`} is a {1:macro}. +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +%%ANKI +Basic +Which library is `noreturn` defined in? +Back: `stdnoreturn.h` +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +%%ANKI +Basic +Consider the following prototype. What is the value of `argv[0]`? +```c +int main(int argc, char* argv[argc + 1]); +``` +Back: The name of the program invocation. +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +%%ANKI +Basic +Consider the following prototype. What is the value of `argv[argc]`? +```c +int main(int argc, char* argv[argc + 1]); +``` +Back: `0` +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +%%ANKI +Basic +Consider the following prototype. What is the value of `argv[1]`? +```c +int main(int argc, char* argv[argc + 1]); +``` +Back: `0` if `argc == 1` else the first argument to the program. +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +%%ANKI +Basic +Consider the following prototype. What is the minimum value of `argc`? +```c +int main(int argc, char* argv[argc + 1]); +``` +Back: `1` +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +%%ANKI +Basic +Consider the following prototype. What is the minimum length of `argv`? +```c +int main(int argc, char* argv[argc + 1]); +``` +Back: `2` +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +## Bibliography + +* “ISO: Programming Languages - C,” April 12, 2011, [https://port70.net/~nsz/c/c11/n1570.pdf](https://port70.net/~nsz/c/c11/n1570.pdf). +* Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). \ No newline at end of file diff --git a/notes/c17/pointers.md b/notes/c17/pointers.md new file mode 100644 index 0000000..f05fdd5 --- /dev/null +++ b/notes/c17/pointers.md @@ -0,0 +1,599 @@ +--- +title: Pointers +TARGET DECK: Obsidian::STEM +FILE TAGS: c17::pointer +tags: + - c17 +--- + +## Overview + +Pointers have the same size as the machine's word size since it should be able to refer to any virtual address. All pointers are either **valid**, **null**, or **indeterminate**. + +%%ANKI +Basic +*Why* does a pointer's size match the machine's word size? +Back: Because it should be able to refer to any virtual address. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +How is a pointer represented in binary? +Back: N/A. This is implementation specific. +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +%%ANKI +Basic +What three states can a pointer be in? +Back: Valid, null, or indeterminate. +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +%%ANKI +Basic +How is a pointer made null? +Back: By initializing or assigning the pointer to `0`. +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +%%ANKI +Basic +When does a pointer evaluate to `false`? +Back: When it is a null pointer. +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +%%ANKI +Basic +When does a pointer evaluate to `true`? +Back: When it is not a null pointer. +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +%%ANKI +Basic +Suppose a pointer logically evaluates to `true`. Why might it still be unsafe to use? +Back: Logical evaluation can't distinguish valid pointers from indeterminate pointers. +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +%%ANKI +Basic +What is the result of dereferencing an indeterminate pointer? +Back: Undefined behavior. +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +%%ANKI +Basic +What is the result of dereferencing a null pointer? +Back: Undefined behavior. +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +%%ANKI +Basic +How is `r->field` equivalently written using `*`? +Back: `(*r).field` +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +How is `(*r).field` more compactly written? +Back: `r->field` +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +How many members *must* be defined in a `struct` initializer? +Back: One. +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +%%ANKI +Basic +Are `struct`s passed by reference or value? +Back: Value. +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +C allows arithmetic on pointers, where the computed value is scaled according to the size of the data type referenced by the pointer. + +%%ANKI +Basic +How is the following (assumed valid) expression simplified? +```c +*&E +``` +Back: As just `E`. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +How is the following (assumed valid) expression simplified? +```c +&*E +``` +Back: As just `E`. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Cloze +Pointer arithmetic {`*(A + i)`} is equivalent to array reference `A[i]`. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +How do we rewrite the return statement using pointer arithmetic? +```c +int func() { + int A[3][4]; + return A[1][2]; +} +``` +Back: `return *(A + 6);` +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +How do we rewrite the return statement using pointer arithmetic? +```c +int func() { + int A[3][4]; + return A[2][0]; +} +``` +Back: `return *(A + 8);` +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +How do we rewrite the return statement using pointer arithmetic? +```c +int func() { + int A[4][3]; + return A[1][2]; +} +``` +Back: `return *(A + 5);` +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +How do we rewrite the return statement using pointer arithmetic? +```c +int func() { + int A[4][3]; + return A[1][0]; +} +``` +Back: `return *(A + 3);` +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +How is the `return` statement likely translated to x86-64? +```c +int* func(int *E) { return E; } +``` +Back: +```asm +movq %rdi,%rax +``` +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. +Tags: x86-64 + +END%% + +%%ANKI +Basic +How is the `return` statement likely translated to x86-64? +```c +int func(int *E) { return E[0]; } +``` +Back: +```asm +movl (%rdi),%eax +``` +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. +Tags: x86-64 + +END%% + +%%ANKI +Basic +How is the `return` statement likely translated to x86-64? +```c +int func(int *E, int i) { return E[i]; } +``` +Back: +```asm +movl (%rdi, %rsi, 4),%eax +``` +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. +Tags: x86-64 + +END%% + +%%ANKI +Basic +How is the `return` statement likely translated to x86-64? +```c +int* func(int *E) { return &E[2]; } +``` +Back: +```asm +leaq 8(%rdi),%rax +``` +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. +Tags: x86-64 + +END%% + +%%ANKI +Basic +Suppose `char *p` has address `S`. What is the result of the following? +```c +(int *) p + 7 +``` +Back: `S + 28` +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +Suppose `char *p` has address `S`. What is the result of the following? +```c +(int *) (p + 7) +``` +Back: `S + 7` +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +How do we declare a function pointer `fp` to the following? +```c +int foo(int x, int *p); +``` +Back: +```c +int (*fp)(int, int *); +``` +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +What do the following two lines declare instances of? +```c +int (*fp)(int, int *); +int *fp(int, int *); +``` +Back: The first is a function pointer. The second is a function. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +What is the value of a function pointer? +Back: The address of the first instruction in the function's machine-code representation. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +Basic +Trap representations are most relevant to what kind of derivied type? +Back: Pointers. +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +%%ANKI +Basic +What does a trap representation refer to? +Back: An invalid interpretation of a bit pattern as a specific type. +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +%%ANKI +Basic +What happens when accessing an object with a trap representation of its type? +Back: Undefined behavior. +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +%%ANKI +Basic +*Why* must a dereferenced object have the correct designated type? +Back: A trap representation of an object's type leads to undefined behavior. +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +%%ANKI +Basic +Refer to the following. *Why* isn't the pointer addition considered correct? +```c +double A[2] = { 0.0, 1.0 }; +double* p = &A[0] + 2; +``` +Back: N/A. It is. +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +%%ANKI +Basic +Refer to the following. *Why* isn't the pointer addition considered correct? +```c +double A[2] = { 0.0, 1.0 }; +double* p = &A[0] + 3; +``` +Back: Pointers cannot refer to addresses beyond that immediately following the array. +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +%%ANKI +Basic +Refer to the following. What values of `N` yield a valid pointer assignment? +```c +double A[2] = { 0.0, 1.0 }; +double* p = &A[N]; +``` +Back: `0`, `1`, and `2`. +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +%%ANKI +Basic +Refer to the following. What is the first value of `N` that yields an invalid pointer assignment? +```c +double A[2] = { 0.0, 1.0 }; +double* p = &A[N]; +``` +Back: `3` +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +%%ANKI +Basic +Refer to the following. Is the last line a valid dereference? +```c +double A[2] = { 0.0, 1.0 }; +double a = *(&A[1]); +``` +Back: Yes. +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +%%ANKI +Basic +Refer to the following. Is the last line a valid dereference? +```c +double A[2] = { 0.0, 1.0 }; +double a = *(&A[2]); +``` +Back: No. +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +%%ANKI +Cloze +A pointer must point to a {valid object}, or {one position beyond} a valid object, or be {null}. +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +%%ANKI +Basic +Consider the following. At what point *could* the program crash? +```c +double A[] = { 0.0, 1.0 }; +double* p = &A[0] + 2; +double q = *p; +``` +Back: On the third line. +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +%%ANKI +Basic +Consider the following. At what point *could* the program crash? +```c +double A[] = { 0.0, 1.0 }; +double* p = &A[0] + 3; +double q = *p; +``` +Back: On the second line. +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +## NULL + +The `NULL` macro refers to a **null pointer constant**, an ICE with value `0` or such an expression cast to type `void*`. The following table lists some valid values `NULL` can take on: + +| Expansion | Type | +| -------------------------- | -------------------- | +| `0U` | `unsigned` | +| `0` | `signed` | +| `\0` | `signed` | +| Enum constant of value `0` | `signed` | +| `0UL` | `unsigned long` | +| `0L` | `signed long` | +| `0ULL` | `unsigned long long` | +| `0LL` | `signed long long` | +| `(void*)0` | `void*` | + +%%ANKI +Basic +How are null pointer constants defined in terms of ICEs? +Back: As any ICE with value `0` or such an expression cast to type `void*`. +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +%%ANKI +Basic +What *must* the `NULL` macro expand to? +Back: Any null pointer constant. +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +%%ANKI +Basic +Which of the following members of the list are ICEs? +```c +0U, '\0', 0UL, (void*)0, 5LL +``` +Back: `0U`, `\0`, and `0UL`. +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +%%ANKI +Basic +Which of the following members of the list are null pointer constants? +```c +0U, '\0', 0UL, (void*)0, 5LL +``` +Back: `0U`, `\0`, `0UL`, and `(void*)0`. +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +%%ANKI +Basic +Which of the following members of the list could `NULL` be identical to? +```c +0U, '\0', 0UL, (void*)0, 5LL +``` +Back: `0U`, `\0`, `0UL`, and `(void*)0`. +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +%%ANKI +Basic +Which of the following members of the list are pointer constants? +```c +0U, '\0', 0UL, (void*)0, 5LL +``` +Back: Just `(void*)0`. +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +%%ANKI +Basic +Why does Gustedt discourage use of `NULL`? +Back: The type of value it expands to is implementation-specific. +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +%%ANKI +Basic +What is wrong with the following invocation? +```c +printf("%d, %p", 1, NULL); +``` +Back: `NULL` may not refer to a pointer type. +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +%%ANKI +Basic +What value must `NULL` have for the following to be correct? +```c +printf("%d, %p", 1, NULL); +``` +Back: `(void*)0` +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +## Aliasing + +Accessing the same object through different pointers is called **aliasing**. With the exclusion of [[simple#Character Types|character types]], only pointers of the same base type may alias. + +%%ANKI +Basic +What does aliasing refer to? +Back: Accessing the same object through different pointers. +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +%%ANKI +Basic +Is aliasing possible in the following function? +```c +void foo(double const* a, double* b); +``` +Back: Yes. +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +%%ANKI +Basic +Is aliasing possible in the following function? +```c +void foo(double const* a, float* b); +``` +Back: No. +Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). + +END%% + +## Bibliography + +* Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). \ No newline at end of file diff --git a/notes/c17/types/derived.md b/notes/c17/types/derived.md index bee5b36..36404f9 100644 --- a/notes/c17/types/derived.md +++ b/notes/c17/types/derived.md @@ -865,696 +865,11 @@ END%% ## Pointers -Pointers have the same size as the machine's word size since it should be able to refer to any virtual address. All pointers are either **valid**, **null**, or **indeterminate**. - -%%ANKI -Basic -*Why* does a pointer's size match the machine's word size? -Back: Because it should be able to refer to any virtual address. -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -How is a pointer represented in binary? -Back: N/A. This is implementation specific. -Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). - -END%% - -%%ANKI -Basic -What three states can a pointer be in? -Back: Valid, null, or indeterminate. -Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). - -END%% - -%%ANKI -Basic -How is a pointer made null? -Back: By initializing or assigning the pointer to `0`. -Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). - -END%% - -%%ANKI -Basic -When does a pointer evaluate to `false`? -Back: When it is a null pointer. -Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). - -END%% - -%%ANKI -Basic -When does a pointer evaluate to `true`? -Back: When it is not a null pointer. -Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). - -END%% - -%%ANKI -Basic -Suppose a pointer logically evaluates to `true`. Why might it still be unsafe to use? -Back: Logical evaluation can't distinguish valid pointers from indeterminate pointers. -Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). - -END%% - -%%ANKI -Basic -What is the result of dereferencing an indeterminate pointer? -Back: Undefined behavior. -Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). - -END%% - -%%ANKI -Basic -What is the result of dereferencing a null pointer? -Back: Undefined behavior. -Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). - -END%% - -%%ANKI -Basic -How is `r->field` equivalently written using `*`? -Back: `(*r).field` -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -How is `(*r).field` more compactly written? -Back: `r->field` -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -How many members *must* be defined in a `struct` initializer? -Back: One. -Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). - -END%% - -%%ANKI -Basic -Are `struct`s passed by reference or value? -Back: Value. -Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). - -END%% - -C allows arithmetic on pointers, where the computed value is scaled according to the size of the data type referenced by the pointer. - -%%ANKI -Basic -How is the following (assumed valid) expression simplified? -```c -*&E -``` -Back: As just `E`. -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -How is the following (assumed valid) expression simplified? -```c -&*E -``` -Back: As just `E`. -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Cloze -Pointer arithmetic {`*(A + i)`} is equivalent to array reference `A[i]`. -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -How do we rewrite the return statement using pointer arithmetic? -```c -int func() { - int A[3][4]; - return A[1][2]; -} -``` -Back: `return *(A + 6);` -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -How do we rewrite the return statement using pointer arithmetic? -```c -int func() { - int A[3][4]; - return A[2][0]; -} -``` -Back: `return *(A + 8);` -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -How do we rewrite the return statement using pointer arithmetic? -```c -int func() { - int A[4][3]; - return A[1][2]; -} -``` -Back: `return *(A + 5);` -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -How do we rewrite the return statement using pointer arithmetic? -```c -int func() { - int A[4][3]; - return A[1][0]; -} -``` -Back: `return *(A + 3);` -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -How is the `return` statement likely translated to x86-64? -```c -int* func(int *E) { return E; } -``` -Back: -```asm -movq %rdi,%rax -``` -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. -Tags: x86-64 - -END%% - -%%ANKI -Basic -How is the `return` statement likely translated to x86-64? -```c -int func(int *E) { return E[0]; } -``` -Back: -```asm -movl (%rdi),%eax -``` -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. -Tags: x86-64 - -END%% - -%%ANKI -Basic -How is the `return` statement likely translated to x86-64? -```c -int func(int *E, int i) { return E[i]; } -``` -Back: -```asm -movl (%rdi, %rsi, 4),%eax -``` -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. -Tags: x86-64 - -END%% - -%%ANKI -Basic -How is the `return` statement likely translated to x86-64? -```c -int* func(int *E) { return &E[2]; } -``` -Back: -```asm -leaq 8(%rdi),%rax -``` -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. -Tags: x86-64 - -END%% - -%%ANKI -Basic -Suppose `char *p` has address `S`. What is the result of the following? -```c -(int *) p + 7 -``` -Back: `S + 28` -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -Suppose `char *p` has address `S`. What is the result of the following? -```c -(int *) (p + 7) -``` -Back: `S + 7` -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -How do we declare a function pointer `fp` to the following? -```c -int foo(int x, int *p); -``` -Back: -```c -int (*fp)(int, int *); -``` -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -What do the following two lines declare instances of? -```c -int (*fp)(int, int *); -int *fp(int, int *); -``` -Back: The first is a function pointer. The second is a function. -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -What is the value of a function pointer? -Back: The address of the first instruction in the function's machine-code representation. -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -Basic -Trap representations are most relevant to what kind of derivied type? -Back: Pointers. -Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). - -END%% - -%%ANKI -Basic -What does a trap representation refer to? -Back: An invalid interpretation of a bit pattern as a specific type. -Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). - -END%% - -%%ANKI -Basic -What happens when accessing an object with a trap representation of its type? -Back: Undefined behavior. -Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). - -END%% - -%%ANKI -Basic -*Why* must a dereferenced object have the correct designated type? -Back: A trap representation of an object's type leads to undefined behavior. -Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). - -END%% - -%%ANKI -Basic -Refer to the following. *Why* isn't the pointer addition considered correct? -```c -double A[2] = { 0.0, 1.0 }; -double* p = &A[0] + 2; -``` -Back: N/A. It is. -Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). - -END%% - -%%ANKI -Basic -Refer to the following. *Why* isn't the pointer addition considered correct? -```c -double A[2] = { 0.0, 1.0 }; -double* p = &A[0] + 3; -``` -Back: Pointers cannot refer to addresses beyond that immediately following the array. -Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). - -END%% - -%%ANKI -Basic -Refer to the following. What values of `N` yield a valid pointer assignment? -```c -double A[2] = { 0.0, 1.0 }; -double* p = &A[N]; -``` -Back: `0`, `1`, and `2`. -Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). - -END%% - -%%ANKI -Basic -Refer to the following. What is the first value of `N` that yields an invalid pointer assignment? -```c -double A[2] = { 0.0, 1.0 }; -double* p = &A[N]; -``` -Back: `3` -Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). - -END%% - -%%ANKI -Basic -Refer to the following. Is the last line a valid dereference? -```c -double A[2] = { 0.0, 1.0 }; -double a = *(&A[1]); -``` -Back: Yes. -Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). - -END%% - -%%ANKI -Basic -Refer to the following. Is the last line a valid dereference? -```c -double A[2] = { 0.0, 1.0 }; -double a = *(&A[2]); -``` -Back: No. -Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). - -END%% - -%%ANKI -Cloze -A pointer must point to a {valid object}, or {one position beyond} a valid object, or be {null}. -Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). - -END%% - -%%ANKI -Basic -Consider the following. At what point *could* the program crash? -```c -double A[] = { 0.0, 1.0 }; -double* p = &A[0] + 2; -double q = *p; -``` -Back: On the third line. -Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). - -END%% - -%%ANKI -Basic -Consider the following. At what point *could* the program crash? -```c -double A[] = { 0.0, 1.0 }; -double* p = &A[0] + 3; -double q = *p; -``` -Back: On the second line. -Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). - -END%% - -### NULL - -The `NULL` macro refers to a **null pointer constant**, an ICE with value `0` or such an expression cast to type `void*`. The following table lists some valid values `NULL` can take on: - -| Expansion | Type | -| -------------------------- | -------------------- | -| `0U` | `unsigned` | -| `0` | `signed` | -| `\0` | `signed` | -| Enum constant of value `0` | `signed` | -| `0UL` | `unsigned long` | -| `0L` | `signed long` | -| `0ULL` | `unsigned long long` | -| `0LL` | `signed long long` | -| `(void*)0` | `void*` | - -%%ANKI -Basic -How are null pointer constants defined in terms of ICEs? -Back: As any ICE with value `0` or such an expression cast to type `void*`. -Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). - -END%% - -%%ANKI -Basic -What *must* the `NULL` macro expand to? -Back: Any null pointer constant. -Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). - -END%% - -%%ANKI -Basic -Which of the following members of the list are ICEs? -```c -0U, '\0', 0UL, (void*)0, 5LL -``` -Back: `0U`, `\0`, and `0UL`. -Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). - -END%% - -%%ANKI -Basic -Which of the following members of the list are null pointer constants? -```c -0U, '\0', 0UL, (void*)0, 5LL -``` -Back: `0U`, `\0`, `0UL`, and `(void*)0`. -Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). - -END%% - -%%ANKI -Basic -Which of the following members of the list could `NULL` be identical to? -```c -0U, '\0', 0UL, (void*)0, 5LL -``` -Back: `0U`, `\0`, `0UL`, and `(void*)0`. -Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). - -END%% - -%%ANKI -Basic -Which of the following members of the list are pointer constants? -```c -0U, '\0', 0UL, (void*)0, 5LL -``` -Back: Just `(void*)0`. -Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). - -END%% - -%%ANKI -Basic -Why does Gustedt discourage use of `NULL`? -Back: The type of value it expands to is implementation-specific. -Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). - -END%% - -%%ANKI -Basic -What is wrong with the following invocation? -```c -printf("%d, %p", 1, NULL); -``` -Back: `NULL` may not refer to a pointer type. -Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). - -END%% - -%%ANKI -Basic -What value must `NULL` have for the following to be correct? -```c -printf("%d, %p", 1, NULL); -``` -Back: `(void*)0` -Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). - -END%% - -### Aliasing - -Accessing the same object through different pointers is called **aliasing**. With the exclusion of [[simple#Character Types|character types]], only pointers of the same base type may alias. - -%%ANKI -Basic -What does aliasing refer to? -Back: Accessing the same object through different pointers. -Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). - -END%% - -%%ANKI -Basic -Is aliasing possible in the following function? -```c -void foo(double const* a, double* b); -``` -Back: Yes. -Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). - -END%% - -%%ANKI -Basic -Is aliasing possible in the following function? -```c -void foo(double const* a, float* b); -``` -Back: No. -Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). - -END%% +Pointers are another type of derived type. They are listed in more detail [[pointers|here]]. ## Functions -A function `f` without a following opening `(` is converted to a pointer to its start. This is called **function decay**. - -%%ANKI -Basic -What is the effect of function decay? -Back: Evaluation of a function `f` without a following opening `(` is converted to a pointer to its start. -Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). - -END%% - -%%ANKI -Basic -What name is given to the implicit conversion of a function to a pointer? -Back: Function decay. -Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). - -END%% - -%%ANKI -Basic -According to Gustedt, what C feature explains why are there no "function values"? -Back: Function-to-pointer decay. -Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). - -END%% - -%%ANKI -Basic -Why can't functions directly be made arguments to functions? -Back: Because function arguments decay to pointers. -Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). - -END%% - -%%ANKI -Cloze -{1:Function pointers} are to {2:`(...)`} whereas {2:pointers} are to {1:`[...]`}. -Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). - -END%% - -%%ANKI -Basic -In what order are decays, dereferences, address ofs, and calls performed in the following? -```c -f(3); -``` -Back: Decay, call. -Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). - -END%% - -%%ANKI -Basic -In what order are decays, dereferences, address ofs, and calls performed in the following? -```c -(&f)(3); -``` -Back: Address of, call. -Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). - -END%% - -%%ANKI -Basic -In what order are decays, dereferences, address ofs, and calls performed in the following? -```c -(*f)(3); -``` -Back: Decay, dereference, decay, call. -Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). - -END%% - -%%ANKI -Basic -In what order are decays, dereferences, address ofs, and calls performed in the following? -```c -(*&f)(3); -``` -Back: Address of, dereference, decay, call. -Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). - -END%% - -%%ANKI -Basic -In what order are decays, dereferences, address ofs, and calls performed in the following? -```c -(&*f)(3); -``` -Back: Decay, dereference, address of, call. -Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). - -END%% - -%%ANKI -Cloze -{1:Pointers} refer to {2:arrays} whereas {2:function pointers} refer to {1:functions}. -Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). - -END%% +Functions are another type of derived type. They are listed in more detail [[c17/functions|here]]. ## Bibliography diff --git a/notes/calculus/images/postage-function.png b/notes/calculus/images/postage-function.png new file mode 100644 index 0000000000000000000000000000000000000000..6ce82c0d82342230759ed396df61c0fece1d49b1 GIT binary patch literal 10608 zcmeHNXH-S(?XMT&LS{?Ac%k?3X(HQP(V;b zKtOU-L4qP6Nz$vvnYlCX&bx2TTJQZE7NPr`s(q?`1e8FSS&qiW-# z*jr$bQ@O6)cH`5S){|#9Ta>Rpa;b^1!8)tFTJvprRS>QlCs^!gKpd_AXwaOQXv~U; zCE!GA;l_#Vl&6(ORBaMRh~67<1TLlNmu@KxjMx=i)UV9tihJHvP`XV~#L~_{Vy7H$ zA8Ke;c4dU>Hmc&{nTm$bEeA^jP5~@Oeou1Z&HVPIPvs$_sVBVQ8+leW-&x_CVb0HX@~e z`qQgl6uwLms1(1Fs1hM?Xhhpy)e_CHWF);#tIWWSq`8%8lAC&8LcViYAt0bBenW88 zBlzYmQ#i{EeJuTBjBz_#yZ9Z$oDIbrx6{yRJJ~+Z?~&6fxm(=WP4sw)3bl_)bg{cD zb6GIm&v+4KC?zrHICr~f@n?|_=7zFvH{KOdzH2xWj4HoZCg_nfFL2ekosKU?w@;ba zz&K{0DAk%rbx(^rcyR5~hpSx%1iYOmocg%rg1##4OqQ5rXW>%AwC){s)GECQ3AMO4 zS^as{W*n0X9oo-aT>b7WWVMz0&CV#EgP?7^wZqfs+Ez$62iLlO2IXk-zC@%ot&dWH z+bcrey4Jp|aWnhVh1AOFjTfgO(&$#7*vesrDTR^o@fLf;!2#qR;r<{x+{z0CosT03 zE@SP>2pcz7VU(?#HCoum6$_#cg5;HauqYd6G>*#}ZSROt;8}gr!o%fgtH5Ifj_o4AYy4#q94^c<|y){IG#Ud)T-;VsVac7%sd`l(m~D zPJxF9+~@jjeXdw-?cdE~Jbv{8@P~*G3M(Qi3>R^A75U=~51g78F!Jky{&I$gKFCp# zt7s25Pj?%%nim>_lC`=`;r?frN#7^SU^K)Ts@;+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xP(l57Qr#h#OAdad9- z0fEwPQweyM0I(J4%}~%ib8rv<&JWMe=SeEr22COwdiwB*33Je60SSNt%i|0z2hEWB z8}Fl*7aAK8#wCV7r>A@Ec27z|Q`iN17`LvjZivUi8$7-PZs*pt$@C^yY5EJIrl#il z4aWr?AdJ*5ULBC6Fual2Kt)o>+84D(mwVV zqGMxYnPuJiK-cu%kW&Sq&+PI(eZ{qDMMdZEf)Zf*f?C8g)&^T!V! wL?zDg<2zAb5Jhz0a|h1kzxoWq^V$(<^{6U*FC`TGmm36Wsp%j~Rjk7P3-9;5761SM literal 0 HcmV?d00001 diff --git a/notes/calculus/intervals.md b/notes/calculus/intervals.md new file mode 100644 index 0000000..90dea6d --- /dev/null +++ b/notes/calculus/intervals.md @@ -0,0 +1,232 @@ +--- +title: Intervals +TARGET DECK: Obsidian::STEM +FILE TAGS: calculus::intervals +tags: + - calculus +--- + +## Overview + +An interval corresponds to a continuous segment of the real number line. There are a few different types. For all $a, b \in \mathbb{R}$ satisfying $a < b$: + +* $[a, b]$ denotes a **closed interval**, all $x$ satisfying $a \leq x \leq b$; +* $(a, b)$ denotes an **open interval**, all $x$ satisfying $a < x < b$; +* $(a, b]$ denotes a **half-open interval**, all $x$ satisfying $a < x \leq b$; +* $[a, b)$ denotes a half-open interval, all $x$ satisfying $a \leq x < b$. + +%%ANKI +Basic +Let $a, b \in \mathbb{R}$ and consider interval $[a, b]$. How is $a$ and $b$ assumed to relate? +Back: $a < b$ +Reference: Tom M. Apostol, _Calculus, Vol. 1: One-Variable Calculus, with an Introduction to Linear Algebra_, 2nd ed. (New York: Wiley, 1980). + +END%% + +%%ANKI +Cloze +Let $a, b \in \mathbb{R}$ s.t. $a < b$. Then {$[a, b]$} denotes a {closed} interval. +Reference: Tom M. Apostol, _Calculus, Vol. 1: One-Variable Calculus, with an Introduction to Linear Algebra_, 2nd ed. (New York: Wiley, 1980). + +END%% + +%%ANKI +Basic +Let $a, b \in \mathbb{R}$ s.t. $a < b$. How is $[a, b]$ expressed as a chain of inequalities? +Back: As all $x$ satisfying $a \leq x \leq b$. +Reference: Tom M. Apostol, _Calculus, Vol. 1: One-Variable Calculus, with an Introduction to Linear Algebra_, 2nd ed. (New York: Wiley, 1980). + +END%% + +%%ANKI +Cloze +Let $a, b \in \mathbb{R}$ s.t. $a < b$. Then {$(a, b)$} denotes an {open} interval. +Reference: Tom M. Apostol, _Calculus, Vol. 1: One-Variable Calculus, with an Introduction to Linear Algebra_, 2nd ed. (New York: Wiley, 1980). + +END%% + +%%ANKI +Basic +Let $a, b \in \mathbb{R}$ s.t. $a < b$. How is $(a, b)$ expressed as a chain of inequalities? +Back: As all $x$ satisfying $a < x < b$. +Reference: Tom M. Apostol, _Calculus, Vol. 1: One-Variable Calculus, with an Introduction to Linear Algebra_, 2nd ed. (New York: Wiley, 1980). + +END%% + +%%ANKI +Cloze +Let $a, b \in \mathbb{R}$ s.t. $a < b$. Then {$(a, b]$ and $[a, b)$]} denote {half-open} intervals. +Reference: Tom M. Apostol, _Calculus, Vol. 1: One-Variable Calculus, with an Introduction to Linear Algebra_, 2nd ed. (New York: Wiley, 1980). + +END%% + +%%ANKI +Basic +Let $a, b \in \mathbb{R}$ s.t. $a < b$. How is $(a, b]$ expressed as a chain of inequalities? +Back: As all $x$ satisfying $a < x \leq b$. +Reference: Tom M. Apostol, _Calculus, Vol. 1: One-Variable Calculus, with an Introduction to Linear Algebra_, 2nd ed. (New York: Wiley, 1980). + +END%% + +%%ANKI +Basic +Let $a, b \in \mathbb{R}$ s.t. $a < b$. How is $[a, b)$ expressed as a chain of inequalities? +Back: As all $x$ satisfying $a \leq x < b$. +Reference: Tom M. Apostol, _Calculus, Vol. 1: One-Variable Calculus, with an Introduction to Linear Algebra_, 2nd ed. (New York: Wiley, 1980). + +END%% + +%%ANKI +Cloze +Interval {$(a, b)$} is called the {interior} of interval $[a, b]$. +Reference: Tom M. Apostol, _Calculus, Vol. 1: One-Variable Calculus, with an Introduction to Linear Algebra_, 2nd ed. (New York: Wiley, 1980). + +END%% + +## Partitions + +Let $a, b \in \mathbb{R}$ such that $a < b$. A **partition** $P$ of interval $[a, b]$ is a set of points $x_0 = a, x_1, \ldots, x_{n-1}, x_n = b$ satisfying $$x_0 < x_1 < \cdots < x_{n-1} < x_n.$$ + +We use the symbol $P = \{x_0, x_1, \ldots, x_n\}$ to designate this partition. + +%%ANKI +Basic +Let $a, b \in \mathbb{R}$ s.t. $a < b$. What is a partition of interval $[a, b]$? +Back: A set of points $x_0 = a, x_1, \ldots, x_{n-1}, x_n = b$ satisfying $$x_0 < x_1 < \cdots < x_{n-1} < x_n.$$ +Reference: Tom M. Apostol, _Calculus, Vol. 1: One-Variable Calculus, with an Introduction to Linear Algebra_, 2nd ed. (New York: Wiley, 1980). + +END%% + +%%ANKI +Basic +Let $a, b \in \mathbb{R}$ s.t. $a < b$. How is a partition of interval $[a, b]$ denoted? +Back: As $\{a, x_1, \ldots, x_{n-1}, b\}$ where $a < x_1 < \cdots < x_{n-1} < b$. +Reference: Tom M. Apostol, _Calculus, Vol. 1: One-Variable Calculus, with an Introduction to Linear Algebra_, 2nd ed. (New York: Wiley, 1980). + +END%% + +%%ANKI +Basic +Let $a, b \in \mathbb{R}$ s.t. $a < b$ and $P = \{a, x_1, \ldots, x_{n-1}, b\}$ be a partition of $[a, b]$. What are $P$'s closed subintervals? +Back: $[a, x_1]$, $[x_1, x_2]$, $\ldots$, $[x_{n-1}, b]$ +Reference: Tom M. Apostol, _Calculus, Vol. 1: One-Variable Calculus, with an Introduction to Linear Algebra_, 2nd ed. (New York: Wiley, 1980). + +END%% + +%%ANKI +Basic +Let $a, b \in \mathbb{R}$ s.t. $a < b$ and $P = \{a, x_1, \ldots, x_{n-1}, b\}$ be a partition of $[a, b]$. What are $P$'s open subintervals? +Back: $(a, x_1)$, $(x_1, x_2)$, $\ldots$, $(x_{n-1}, b)$ +Reference: Tom M. Apostol, _Calculus, Vol. 1: One-Variable Calculus, with an Introduction to Linear Algebra_, 2nd ed. (New York: Wiley, 1980). + +END%% + +%%ANKI +Basic +Let $a, b \in \mathbb{R}$ s.t. $a < b$ and $P = \{a, x_1, \ldots, x_{n-1}, b\}$ be a partition of $[a, b]$. How are the members of $P$ assumed to relate? +Back: $a < x_1 < \cdots < x_{n-1} < b$ +Reference: Tom M. Apostol, _Calculus, Vol. 1: One-Variable Calculus, with an Introduction to Linear Algebra_, 2nd ed. (New York: Wiley, 1980). + +END%% + +A **refinement** $P'$ of some partition $P$ is created by adjoining more subdivision points to those of $P$. $P'$, also a partition, is said to be **finer** than $P$. + +%%ANKI +Basic +Let $P$ be a partition of $[a, b]$. What is a refinement of $P$? +Back: A partition created by adjoining one or more subdivision points to those of $P$. +Reference: Tom M. Apostol, _Calculus, Vol. 1: One-Variable Calculus, with an Introduction to Linear Algebra_, 2nd ed. (New York: Wiley, 1980). + +END%% + +%%ANKI +Basic +Let $P'$ be a refinement on partition $P$ of $[a, b]$. How do $P$ and $P'$ relate? +Back: $P \subseteq P'$ +Reference: Tom M. Apostol, _Calculus, Vol. 1: One-Variable Calculus, with an Introduction to Linear Algebra_, 2nd ed. (New York: Wiley, 1980). + +END%% + +%%ANKI +Basic +Let $P'$ be a refinement on partition $P$ of $[a, b]$. Which of $P$ or $P'$ have more subdivision points? +Back: $P'$ +Reference: Tom M. Apostol, _Calculus, Vol. 1: One-Variable Calculus, with an Introduction to Linear Algebra_, 2nd ed. (New York: Wiley, 1980). + +END%% + +%%ANKI +Cloze +Let $P'$ be a refinement on partition $P$ of $[a, b]$. Then $P'$ is said to be {finer} than $P$. +Reference: Tom M. Apostol, _Calculus, Vol. 1: One-Variable Calculus, with an Introduction to Linear Algebra_, 2nd ed. (New York: Wiley, 1980). + +END%% + +## Step Functions + +A function $s$, whose domain is a closed interval $[a, b]$, is called a **step function** if and only if there exists a [[#Partitions|partition]] $P = \{a, x_1, \ldots, x_{n-1}, b\}$ of $[a, b]$ such that $s$ is constant on each open subinterval of $P$. + +> At each of the endpoints $x_{k-1}$ and $x_k$, the function must have some well-defined value. + +Step functions are also called **piecewise constant functions**. + +%%ANKI +Basic +With maximum specificity, what is the domain of a step function? +Back: A closed interval. +Reference: Tom M. Apostol, _Calculus, Vol. 1: One-Variable Calculus, with an Introduction to Linear Algebra_, 2nd ed. (New York: Wiley, 1980). + +END%% + +%%ANKI +Basic +Suppose $s$ is a step function with domain $[a, b]$. This implies existence of what? +Back: A partition of $[a, b]$ such that $s$ is constant on each open subinterval. +Reference: Tom M. Apostol, _Calculus, Vol. 1: One-Variable Calculus, with an Introduction to Linear Algebra_, 2nd ed. (New York: Wiley, 1980). + +END%% + +%%ANKI +Basic +Let $s$ be a step function on $[a, b]$. What of its corresponding partition must be constant? +Back: The value along each open subinterval. +Reference: Tom M. Apostol, _Calculus, Vol. 1: One-Variable Calculus, with an Introduction to Linear Algebra_, 2nd ed. (New York: Wiley, 1980). + +END%% + +%%ANKI +Basic +Let $s$ be a step function on $[a, b]$ with partition $P$. What criteria must the endpoints of $P$'s open subintervals satisfy? +Back: They must be well-defined. +Reference: Tom M. Apostol, _Calculus, Vol. 1: One-Variable Calculus, with an Introduction to Linear Algebra_, 2nd ed. (New York: Wiley, 1980). + +END%% + +%%ANKI +Cloze +{Step} functions are also called {piecewise constant} functions. +Reference: Tom M. Apostol, _Calculus, Vol. 1: One-Variable Calculus, with an Introduction to Linear Algebra_, 2nd ed. (New York: Wiley, 1980). + +END%% + +%%ANKI +Basic +The following is an example of what kind of function? +![[postage-function.png]] +Back: A step function. +Reference: Tom M. Apostol, _Calculus, Vol. 1: One-Variable Calculus, with an Introduction to Linear Algebra_, 2nd ed. (New York: Wiley, 1980). + +END%% + +%%ANKI +Basic +What minimally refined partition is associated with the following step function? +![[postage-function.png]] +Back: $\{0, 1, 2, 3, 4\}$ +Reference: Tom M. Apostol, _Calculus, Vol. 1: One-Variable Calculus, with an Introduction to Linear Algebra_, 2nd ed. (New York: Wiley, 1980). + +END%% + +## Bibliography + +* Tom M. Apostol, _Calculus, Vol. 1: One-Variable Calculus, with an Introduction to Linear Algebra_, 2nd ed. (New York: Wiley, 1980). \ No newline at end of file diff --git a/notes/set/cardinality.md b/notes/set/cardinality.md index 8c28ab1..1171cf4 100644 --- a/notes/set/cardinality.md +++ b/notes/set/cardinality.md @@ -8,7 +8,7 @@ tags: ## Equinumerosity -We say set $A$ is **equinumerous** to set $B$, written ($A \approx B$) if and only if there exists a [[functions#Injections|one-to-one]] function from $A$ [[functions#Surjections|onto]] $B$. +We say set $A$ is **equinumerous** to set $B$, written ($A \approx B$) if and only if there exists a [[set/functions#Injections|one-to-one]] function from $A$ [[set/functions#Surjections|onto]] $B$. %%ANKI Basic