From a0c7a4e2a8e04ec14fdbbd1722ce4f7f74a9ec55 Mon Sep 17 00:00:00 2001 From: Joshua Potter Date: Sat, 24 Aug 2024 18:48:32 -0600 Subject: [PATCH] Better classify types according to ISO C11. --- .../plugins/obsidian-to-anki-plugin/data.json | 17 +- notes/_journal/2024-08/2024-08-16.md | 2 +- notes/c17/declarations.md | 372 ----------------- notes/c17/index.md | 99 ----- notes/c17/pointers.md | 23 - notes/c17/types/derived.md | 119 ++++++ notes/c17/types/index.md | 395 ++++++++++++++++++ notes/c17/{types.md => types/simple.md} | 315 +++++++++++++- 8 files changed, 837 insertions(+), 505 deletions(-) delete mode 100644 notes/c17/pointers.md create mode 100644 notes/c17/types/derived.md create mode 100644 notes/c17/types/index.md rename notes/c17/{types.md => types/simple.md} (64%) diff --git a/notes/.obsidian/plugins/obsidian-to-anki-plugin/data.json b/notes/.obsidian/plugins/obsidian-to-anki-plugin/data.json index b2c704e..0e74f13 100644 --- a/notes/.obsidian/plugins/obsidian-to-anki-plugin/data.json +++ b/notes/.obsidian/plugins/obsidian-to-anki-plugin/data.json @@ -310,9 +310,9 @@ "_journal/2024-02-23.md": "219ce9ad15a8733edd476c97628b71fd", "_journal/2024-02/2024-02-22.md": "312e55d57868026f6e80f7989a889c2b", "c17/strings.md": "2da50edd26eae35c81f70e65bbd12d49", - "c17/index.md": "fd48bc8d8b9b28702e8fdf0f4cf977d5", + "c17/index.md": "2139482226954123756e45c2190ec4a8", "c17/escape-sequences.md": "a8b99070336878b4e8c11e9e4525a500", - "c17/declarations.md": "2b61706906d8ae935e0b56e962ad2fa8", + "c17/declarations.md": "bca29aef30d349ca6be5436741486930", "algorithms/sorting/merge-sort.md": "6506483f7df6507cee0407bd205dbedd", "_journal/2024-02-24.md": "9bb319d5014caf962a9ce3141076cff4", "_journal/2024-02/2024-02-23.md": "0aad297148e8cc4058b48b7e45787ca7", @@ -748,7 +748,7 @@ "_journal/2024-08-16.md": "a25c680684bcffc6a38cebbb448d9d97", "_journal/2024-08/2024-08-15.md": "7c3a96a25643b62b0064bf32cb17d92f", "_journal/2024-08-17.md": "b06a551560c377f61a1b39286cd43cee", - "_journal/2024-08/2024-08-16.md": "096d9147a9e3e7a947558f8dec763a2c", + "_journal/2024-08/2024-08-16.md": "da1127a1985074a3930b4c3512344025", "set/order.md": "66581eb2d882569b1591e660601caa55", "_journal/2024-08-18.md": "6f8aec69e00401b611db2a377a3aace5", "ontology/philosophy/properties.md": "41b32249d3e4c23d73ddb3a417d65a4c", @@ -769,7 +769,16 @@ "set/natural-numbers.md": "97ca466daf1173ed8973db1d1a1935cc", "_journal/2024-08-24.md": "563fad24740e44734a87d7c3ec46cec4", "_journal/2024-08/2024-08-23.md": "7b5a40e83d8f07ff54cd9708017d029c", - "_journal/2024-08/2024-08-22.md": "050235d5dc772b542773743b57ce3afe" + "_journal/2024-08/2024-08-22.md": "050235d5dc772b542773743b57ce3afe", + "c17/fixed-width.md": "b5f2342f3e8804978aad415ca7bc8b86", + "c17/enums.md": "9414fb67aa256a0a11b7240534c67bf6", + "c17/derived-types.md": "6fb8f23a2423f05d5bdccb6672a32e38", + "c17/basic-types.md": "7c6653bf6dc24c2f2aa72fc95c4f7875", + "c17/types/simple.md": "71f1bea1c8961c01325c24c6ad6007f6", + "c17/types/enumerated.md": "e1f70a30677c776b7b44ac3e0ff4e76d", + "c17/types/derived.md": "aff0d2b6d218fb67af3cc92ead924de3", + "c17/types/basic.md": "5064e21e683c0218890058882e06b6f3", + "c17/types/index.md": "b3e4f47b5f1f2a76d1d039e6263a41b8" }, "fields_dict": { "Basic": [ diff --git a/notes/_journal/2024-08/2024-08-16.md b/notes/_journal/2024-08/2024-08-16.md index 41ac6ff..e133fc1 100644 --- a/notes/_journal/2024-08/2024-08-16.md +++ b/notes/_journal/2024-08/2024-08-16.md @@ -9,4 +9,4 @@ title: "2024-08-16" - [ ] Korean (Read 1 Story) * Notes on [[relations#Preorders|preorders]] and [[relations#Partial Orders|partial orders]]. -* Details on C's [[c17/index|abstract state machine]] and [[types|integer types]]. \ No newline at end of file +* Details on C's [[c17/index|abstract state machine]] and [[basic|integer types]]. \ No newline at end of file diff --git a/notes/c17/declarations.md b/notes/c17/declarations.md index 59bb318..c266cd4 100644 --- a/notes/c17/declarations.md +++ b/notes/c17/declarations.md @@ -323,378 +323,6 @@ Reference: Van der Linden, Peter. _Expert C Programming: Deep C Secrets_. Progra END%% -### Type Specifiers - -Signed | Unsigned | 32-bit | 64-bit ------------ | ------------------- | ------ | ------ -signed char | unsigned char | 1 | 1 -short | unsigned short | 2 | 2 -int | unsigned | 4 | 4 -long | unsigned long | 4 | 8 -long long | unsigned long long | 8 | 8 -char * | - | 4 | 8 -float | - | 4 | 4 -double | - | 8 | 8 - -Fixed width data integral types (e.g. `int32_t`) can be found by including ``. - -%%ANKI -Cloze -The {``} header file contains {fixed width data integral types}. -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 -Which header file contains `INT32_MAX`? -Back: `` -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 does the "width" of an integer type refer to? -Back: The number of bits used to represent its value. -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -%%ANKI -What two variants does a C integral type declaration have? -Back: Signed and unsigned. -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. -END%% - -%%ANKI -What does it mean for an integer to be "signed"? -Back: It can represent negative, zero, and positive values. -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. -END%% - -%%ANKI -What does it mean for an integer to be "unsigned"? -Back: It can only represent nonnegative values. -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 large is a word? -Back: This is a machine-dependent value. -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 word sizes are typical nowadays? -Back: 32- and 64-bit word sizes. -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 -`char` *typically* represents {1} byte(s) on a 64-bit platform. -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 -`short` *typically* represents {2} byte(s) on a 64-bit platform. -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 -`int` *typically* represents {4} bytes(s) on a 64-bit platform. -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 -`unsigned` *typically* represents {4} bytes(s) on a 64-bit platform. -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 -`long` *typically* represents {8} bytes(s) on a 64-bit platform. -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 -`long long` *typically* represents {8} bytes(s) on a 64-bit platform. -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 distinguishes `long` from `long long`? -Back: `long long`s are guaranteed to be at least 64-bit wide. -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 -*Why* is there both a `long` and `long long`? -Back: `long long`s are at least 64-bit wide, even on 32-bit platforms. -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 -`char *` *typically* represents {8} bytes(s) on a 64-bit platform. -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 -`float` *typically* represents {4} bytes(s) on a 64-bit platform. -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 -`double` *typically* represents {8} bytes(s) on a 64-bit platform. -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 -Is declaration `int` signed or unsigned? -Back: Signed. -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 declaration `unsigned` written more precisely? -Back: `unsigned 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 -Is declaration `long` signed or unsigned? -Back: Signed. -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 -{1:`float`} has {2:4} byte precision whereas {2:`double`} has {1:8} byte precision. -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 -The C standard defines {lower} bounds on numeric ranges of data types. -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 -The C standard does *not* define {1:upper} bounds on numeric ranges of data types (except for {1:fixed-size} types). -Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. - -END%% - -### Structs - -A `struct` is a grouping of data together. It has the following general form: - -```c -struct optional_tag { - type_1 ident1; - ... - type_N identN; -} optional_var1 ... optional_varM; -``` - -%%ANKI -Basic -What is the underlined portion of the following declaration called? -```c -struct ___ { ... }; -``` -Back: The tag. -Reference: Van der Linden, Peter. _Expert C Programming: Deep C Secrets_. Programming Languages / C. Mountain View, Cal.: SunSoft Pr, 1994. - -END%% - -%%ANKI -Basic -What distinguishes the `X`'s from one another in the following? -```c -struct X { ... } X; -``` -Back: The first `X` is a tag whereas the second is a variable with type `struct X`. -Reference: Van der Linden, Peter. _Expert C Programming: Deep C Secrets_. Programming Languages / C. Mountain View, Cal.: SunSoft Pr, 1994. - -END%% - -%%ANKI -Basic -What distinguishes the `X`'s from one another in the following? -```c -typedef struct X { ... } X; -``` -Back: The first `X` is a tag whereas the second is an alias for type `struct X`. -Reference: Van der Linden, Peter. _Expert C Programming: Deep C Secrets_. Programming Languages / C. Mountain View, Cal.: SunSoft Pr, 1994. - -END%% - -### Unions - -A `union` is a grouping of data together but with overlaid storage. It has the following general form: - -```c -union optional_tag { - type1 ident1; - ... - typeN identN; -} optional_var1 ... optional_varN; -``` - -%%ANKI -Basic -What is the underlined portion of the following declaration called? -```c -union ___ { ... }; -``` -Back: The tag. -Reference: Van der Linden, Peter. _Expert C Programming: Deep C Secrets_. Programming Languages / C. Mountain View, Cal.: SunSoft Pr, 1994. - -END%% - -%%ANKI -Basic -What distinguishes the `X`'s from one another in the following? -```c -union X { ... } X; -``` -Back: The first `X` is a tag whereas the second is a variable with type `union X`. -Reference: Van der Linden, Peter. _Expert C Programming: Deep C Secrets_. Programming Languages / C. Mountain View, Cal.: SunSoft Pr, 1994. - -END%% - -%%ANKI -Basic -What distinguishes the `X`'s from one another in the following? -```c -typedef union X { ... } X; -``` -Back: The first `X` is a tag whereas the second is an alias for type `union X`. -Reference: Van der Linden, Peter. _Expert C Programming: Deep C Secrets_. Programming Languages / C. Mountain View, Cal.: SunSoft Pr, 1994. - -END%% - -### Enums - -An `enum` is a mapping of identifiers with integer values. They have general form: - -```c -enum optional_tag { - type1 ident1; - ... - typeN identN; -} optional_var1 ... optional_varN; -``` - -%%ANKI -Basic -What is the underlined portion of the following declaration called? -```c -enum ___ { ... }; -``` -Back: The tag. -Reference: Van der Linden, Peter. _Expert C Programming: Deep C Secrets_. Programming Languages / C. Mountain View, Cal.: SunSoft Pr, 1994. - -END%% - -%%ANKI -Basic -What distinguishes the `X`'s from one another in the following? -```c -enum X { ... } X; -``` -Back: The first `X` is a tag whereas the second is a variable with type `enum X`. -Reference: Van der Linden, Peter. _Expert C Programming: Deep C Secrets_. Programming Languages / C. Mountain View, Cal.: SunSoft Pr, 1994. - -END%% - -%%ANKI -Basic -What distinguishes the `X`'s from one another in the following? -```c -typedef enum X { ... } X; -``` -Back: The first `X` is a tag whereas the second is an alias for type `enum X`. -Reference: Van der Linden, Peter. _Expert C Programming: Deep C Secrets_. Programming Languages / C. Mountain View, Cal.: SunSoft Pr, 1994. - -END%% - -%%ANKI -Basic -What is the value of `A` in the following? -```c -enum X { A, B, C }; -``` -Back: `0` -Reference: Van der Linden, Peter. _Expert C Programming: Deep C Secrets_. Programming Languages / C. Mountain View, Cal.: SunSoft Pr, 1994. - -END%% - -%%ANKI -Basic -What is the value of `B` in the following? -```c -enum X { A, B, C }; -``` -Back: `1` -Reference: Van der Linden, Peter. _Expert C Programming: Deep C Secrets_. Programming Languages / C. Mountain View, Cal.: SunSoft Pr, 1994. - -END%% - -%%ANKI -Basic -What is the value of `B` in the following? -```c -enum X { A=2, B, C }; -``` -Back: `3` -Reference: Van der Linden, Peter. _Expert C Programming: Deep C Secrets_. Programming Languages / C. Mountain View, Cal.: SunSoft Pr, 1994. - -END%% - -%%ANKI -Basic -According to Linden, what is the "only advantage" of `enum`s over `#define`? -Back: `enum`s can usually be traced in a debugger. -Reference: Van der Linden, Peter. _Expert C Programming: Deep C Secrets_. Programming Languages / C. Mountain View, Cal.: SunSoft Pr, 1994. - -END%% - ## Bibliography * Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. diff --git a/notes/c17/index.md b/notes/c17/index.md index 00b7240..91254d6 100644 --- a/notes/c17/index.md +++ b/notes/c17/index.md @@ -337,8 +337,6 @@ END%% Types are additional properties that C associates with values. All values have a type that is statically determined and all possible operations on a value are determined by its type. -Types are categorized as function types and object types. An object type is **complete** if there is sufficient information to determine the size of objects of that type. Otherwise we say it is **incomplete**. - %%ANKI Cloze Possible operations on a {value} are determined by its {type}. @@ -346,103 +344,6 @@ Reference: Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co END%% -%%ANKI -Basic -Types are partitioned into what two categories? -Back: Object types and function types. -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 is an object type? -Back: A type that describes objects. -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 is a function type? -Back: A type that describes functions. -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 parts characterize a function type? -Back: The return type and the number/types of its parameters. -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 does it mean for an object type to be complete? -Back: There is sufficient information to determine the size of objects of that type. -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 does it mean for an object type to be incomplete? -Back: There is insufficient information to determine the size of objects of that type. -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 -Does `x` have complete or incomplete object type in the following? -```c -void x; -``` -Back: Incomplete. -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 -Does `x` have complete or incomplete object type in the following? -```c -int x; -``` -Back: Complete. -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 -Does `x` have complete or incomplete object type in the following? -```c -void *x; -``` -Back: Complete. -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 object type can an lvalue *not* have? -Back: `void` -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 object type can an lvalue have? -Back: Any object type other than `void`. -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%% - ## Representation The **binary representation** of a type is the model used to represent values of said type on a given platform. The **object representation** of a type determines how values are stored in memory, disk, etc. diff --git a/notes/c17/pointers.md b/notes/c17/pointers.md deleted file mode 100644 index f7a5e4e..0000000 --- a/notes/c17/pointers.md +++ /dev/null @@ -1,23 +0,0 @@ ---- -title: Pointers -TARGET DECK: Obsidian::STEM -FILE TAGS: c17 -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. - -%%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%% - -## Bibliography - -* Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. \ No newline at end of file diff --git a/notes/c17/types/derived.md b/notes/c17/types/derived.md new file mode 100644 index 0000000..76c0093 --- /dev/null +++ b/notes/c17/types/derived.md @@ -0,0 +1,119 @@ +--- +title: Derived Types +TARGET DECK: Obsidian::STEM +FILE TAGS: c17::type +tags: + - c17 +--- + +## Overview + +TODO + +## Pointers + +Pointers have the same size as the machine's word size since it should be able to refer to any virtual address. + +%%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%% + +## Structures + +A `struct` is a grouping of data together. It has the following general form: + +```c +struct optional_tag { + type_1 ident1; + ... + type_N identN; +} optional_var1 ... optional_varM; +``` + +%%ANKI +Basic +What is the underlined portion of the following declaration called? +```c +struct ___ { ... }; +``` +Back: The tag. +Reference: Van der Linden, Peter. _Expert C Programming: Deep C Secrets_. Programming Languages / C. Mountain View, Cal.: SunSoft Pr, 1994. + +END%% + +%%ANKI +Basic +What distinguishes the `X`'s from one another in the following? +```c +struct X { ... } X; +``` +Back: The first `X` is a tag whereas the second is a variable with type `struct X`. +Reference: Van der Linden, Peter. _Expert C Programming: Deep C Secrets_. Programming Languages / C. Mountain View, Cal.: SunSoft Pr, 1994. + +END%% + +%%ANKI +Basic +What distinguishes the `X`'s from one another in the following? +```c +typedef struct X { ... } X; +``` +Back: The first `X` is a tag whereas the second is an alias for type `struct X`. +Reference: Van der Linden, Peter. _Expert C Programming: Deep C Secrets_. Programming Languages / C. Mountain View, Cal.: SunSoft Pr, 1994. + +END%% + +## Unions + +A `union` is a grouping of data together but with overlaid storage. It has the following general form: + +```c +union optional_tag { + type1 ident1; + ... + typeN identN; +} optional_var1 ... optional_varN; +``` + +%%ANKI +Basic +What is the underlined portion of the following declaration called? +```c +union ___ { ... }; +``` +Back: The tag. +Reference: Van der Linden, Peter. _Expert C Programming: Deep C Secrets_. Programming Languages / C. Mountain View, Cal.: SunSoft Pr, 1994. + +END%% + +%%ANKI +Basic +What distinguishes the `X`'s from one another in the following? +```c +union X { ... } X; +``` +Back: The first `X` is a tag whereas the second is a variable with type `union X`. +Reference: Van der Linden, Peter. _Expert C Programming: Deep C Secrets_. Programming Languages / C. Mountain View, Cal.: SunSoft Pr, 1994. + +END%% + +%%ANKI +Basic +What distinguishes the `X`'s from one another in the following? +```c +typedef union X { ... } X; +``` +Back: The first `X` is a tag whereas the second is an alias for type `union X`. +Reference: Van der Linden, Peter. _Expert C Programming: Deep C Secrets_. Programming Languages / C. Mountain View, Cal.: SunSoft Pr, 1994. + +END%% + +## Bibliography + +* Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. +* “ISO: Programming Languages - C,” April 12, 2011, [https://port70.net/~nsz/c/c11/n1570.pdf](https://port70.net/~nsz/c/c11/n1570.pdf). +* Van der Linden, Peter. _Expert C Programming: Deep C Secrets_. Programming Languages / C. Mountain View, Cal.: SunSoft Pr, 1994. \ No newline at end of file diff --git a/notes/c17/types/index.md b/notes/c17/types/index.md new file mode 100644 index 0000000..c51585f --- /dev/null +++ b/notes/c17/types/index.md @@ -0,0 +1,395 @@ +--- +title: Types +TARGET DECK: Obsidian::STEM +FILE TAGS: c17::type +tags: + - c17 +--- + +## Overview + +Types in C are categorized corresponding to a hierarchy with a foundation comprising of the [[simple|simple types]]. These types are then grouped and further categorized until we reach the top of the hierarchy consisting of all types. + +%%ANKI +Basic +What is the foundational category of types? +Back: The simple types. +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 are "simple types" named the way they are? +Back: These types are primitives in the type hierarchy. +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 are "real types" named the way they are? +Back: They refer to types that belong to $\mathbb{R}$. +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 are "real types" named the way they are? +Back: They refer to types that belong to $\mathbb{C}$. +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%% + +All types are categorized as **function types** or **object types**. An object type is **complete** if there is sufficient information to determine the size of objects of that type. Otherwise we say it is **incomplete**. + +%%ANKI +Basic +Types are partitioned into what two top-level categories? +Back: Object types and function types. +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 is an object type? +Back: A type that describes objects. +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 is a function type? +Back: A type that describes functions. +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 parts characterize a function type? +Back: The return type and the number/types of its parameters. +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 does it mean for an object type to be complete? +Back: There is sufficient information to determine the size of objects of that type. +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 does it mean for an object type to be incomplete? +Back: There is insufficient information to determine the size of objects of that type. +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 +Does `x` have complete or incomplete object type in the following? +```c +void x; +``` +Back: Incomplete. +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 +Does `x` have complete or incomplete object type in the following? +```c +int x; +``` +Back: Complete. +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 +Does `x` have complete or incomplete object type in the following? +```c +void *x; +``` +Back: Complete. +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 object type can an lvalue *not* have? +Back: `void` +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 object type can an lvalue have? +Back: Any object type other than `void`. +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%% + +## Basic Types + +The **basic types** comprise of `char`, the signed/unsigned integer types, and the floating point types. All basic types are complete object types. + +%%ANKI +Basic +Are the basic types a subset of object types or function types? +Back: Object types. +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 +The basic types consist of what simple types? +Back: `char`, signed/unsigned integer types, and the floating point types. +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 `int` considered a basic type? +Back: Yes. +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 `char` considered a simple type? +Back: Yes. +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 `float complex` considered a simple type? +Back: Yes. +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%% + +## Integer Types + +The **integer types** comprise of `char`, the signed/unsigned integer types, and `enum`s. + +%%ANKI +Basic +Are the integer types a subset of object types or function types? +Back: Object types. +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 +The integer types consist of what simple types? +Back: `char`, signed/unsigned integer types, and `enum`s. +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 `enum` considered a simple type? +Back: Yes. +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 `enum` considered a basic type? +Back: No. +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 `enum` considered a complex type? +Back: No. +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 `enum` considered a real type? +Back: Yes. +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 category of types is considered a basic type but not an integer type? +Back: Floating point types. +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 category of types is considered an integer type but not a basic type? +Back: Enumerated types. +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 types are considered both basic types and integer types? +Back: `char` and the signed/unsigned integer types. +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 basic types or integer types is a subset of the other? +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%% + +## Arithmetic Types + +Integer and floating point types are collectively called **arithmetic types**. Each arithmetic type belongs to one **type domain**: the **real type domain** comprises the real types and the **complex type domain** comprises the complex types. + +%%ANKI +Cloze +Integer and floating point types are collectively called {arithmetic} types. +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 +Cloze +The {real} types contrast the {complex} types. +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 two smaller category of types make up the arithmetic types? +Back: The integer and floating point types. +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 +The arithmetic types are categorized into what type domains? +Back: The real type domain and the complex type domain. +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 type domain does `int` fall under? +Back: The real type domain. +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 type domain does `float complex` fall under? +Back: The complex type domain. +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 type domain does `float` fall under? +Back: The real type domain. +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 type domain does `long double` fall under? +Back: The real type domain. +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 type domain does `bool` fall under? +Back: The real type domain. +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 type domain does `double complex` fall under? +Back: The complex type domain. +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 basic types or arithmetic types is a subset of the other? +Back: Basic types is a subset of arithmetic types. +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 arithmetic types or integer types is a subset of the other? +Back: Integer types is a subset of arithmetic types. +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 the real types or integer types is a subset of the other? +Back: The integer types is a subset of the real types. +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 the real types or floating point types is a subset of the other? +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 +Which types belong to the intersection of real and floating point types? +Back: Floating point types in the real type domain. +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%% + +## Bibliography + +* “ISO: Programming Languages - C,” April 12, 2011, [https://port70.net/~nsz/c/c11/n1570.pdf](https://port70.net/~nsz/c/c11/n1570.pdf). \ No newline at end of file diff --git a/notes/c17/types.md b/notes/c17/types/simple.md similarity index 64% rename from notes/c17/types.md rename to notes/c17/types/simple.md index 8b18ca1..7c3c7f3 100644 --- a/notes/c17/types.md +++ b/notes/c17/types/simple.md @@ -1,16 +1,231 @@ --- -title: Types +title: Simple Types TARGET DECK: Obsidian::STEM -FILE TAGS: c17 +FILE TAGS: c17::type tags: - c17 --- ## Overview -C has a series of basic types and means of constructing derived types from them. +The bottom of the type hierarchy consists of **simple types**. This comprises the primitive types that all other types are either based off of or derived from. -## Integers +| Signed | Unsigned | 32-bit | 64-bit | +| ------------- | -------------------- | ------ | ------ | +| - | `bool` | 1 | 1 | +| `signed char` | `unsigned char` | 1 | 1 | +| `short` | `unsigned short` | 2 | 2 | +| `int` | `unsigned` | 4 | 4 | +| `long` | `unsigned long` | 4 | 8 | +| `long long` | `unsigned long long` | 8 | 8 | + +| Real | Complex | 32-bit | 64-bit | +| ------------- | --------------------- | ------ | ------ | +| `float` | - | 4 | 4 | +| `double` | - | 8 | 8 | +| `long double` | - | - | - | +| - | `float complex` | 4 | 4 | +| - | `double complex` | 8 | 8 | +| - | `long double complex` | - | - | + +%%ANKI +Cloze +The {``} header file contains {fixed width data integral types}. +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 +The integer types are grouped into what two classes? +Back: The signed and unsigned integer types. +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 +The floating point types are grouped into what two classes? +Back: The real and complex floating point types. +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 header file contains `INT32_MAX`? +Back: `` +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 does the "width" of an integer type refer to? +Back: The number of bits used to represent its value. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +%%ANKI +What two variants does a C integral type declaration have? +Back: Signed and unsigned. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. +END%% + +%%ANKI +What does it mean for an integer to be "signed"? +Back: It can represent negative, zero, and positive values. +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. +END%% + +%%ANKI +What does it mean for an integer to be "unsigned"? +Back: It can only represent nonnegative values. +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 large is a word? +Back: This is a machine-dependent value. +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 word sizes are typical nowadays? +Back: 32- and 64-bit word sizes. +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 +`char` *typically* represents {1} byte(s) on a 64-bit platform. +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 +`short` *typically* represents {2} byte(s) on a 64-bit platform. +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 +`int` *typically* represents {4} bytes(s) on a 64-bit platform. +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 +`unsigned` *typically* represents {4} bytes(s) on a 64-bit platform. +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 +`long` *typically* represents {8} bytes(s) on a 64-bit platform. +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 +`long long` *typically* represents {8} bytes(s) on a 64-bit platform. +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 distinguishes `long` from `long long`? +Back: `long long`s are guaranteed to be at least 64-bit wide. +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 +*Why* is there both a `long` and `long long`? +Back: `long long`s are at least 64-bit wide, even on 32-bit platforms. +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 +`char *` *typically* represents {8} bytes(s) on a 64-bit platform. +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 +`float` *typically* represents {4} bytes(s) on a 64-bit platform. +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 +`double` *typically* represents {8} bytes(s) on a 64-bit platform. +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 +Is declaration `int` signed or unsigned? +Back: Signed. +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 declaration `unsigned` written more precisely? +Back: `unsigned 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 +Is declaration `long` signed or unsigned? +Back: Signed. +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 +{1:`float`} has {2:4} byte precision whereas {2:`double`} has {1:8} byte precision. +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 +The C standard defines {lower} bounds on numeric ranges of data types. +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 +The C standard does *not* define {1:upper} bounds on numeric ranges of data types (except for {1:fixed-size} types). +Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. + +END%% + +## Characters Type `char` is special since it can be signed or unsigned depending on platform. Keep in mind regardless of its signedness, it is still considered a distinct type from both the `unsigned char` and `signed char` type. @@ -22,6 +237,8 @@ Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Program END%% +## Integers + **Narrow types** cannot be used directly in arithmetic. Instead they are first promoted to a wider type. On almost every system, this promotion will be to a `signed int` of the same value, regardless of the signedness of the narrow type itself. %%ANKI @@ -638,7 +855,93 @@ Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Program END%% +## Enumerated Types + +An `enum` is a mapping of identifiers with integer values. They have general form: + +```c +enum optional_tag { + type1 ident1; + ... + typeN identN; +} optional_var1 ... optional_varN; +``` + +%%ANKI +Basic +What is the underlined portion of the following declaration called? +```c +enum ___ { ... }; +``` +Back: The tag. +Reference: Van der Linden, Peter. _Expert C Programming: Deep C Secrets_. Programming Languages / C. Mountain View, Cal.: SunSoft Pr, 1994. + +END%% + +%%ANKI +Basic +What distinguishes the `X`'s from one another in the following? +```c +enum X { ... } X; +``` +Back: The first `X` is a tag whereas the second is a variable with type `enum X`. +Reference: Van der Linden, Peter. _Expert C Programming: Deep C Secrets_. Programming Languages / C. Mountain View, Cal.: SunSoft Pr, 1994. + +END%% + +%%ANKI +Basic +What distinguishes the `X`'s from one another in the following? +```c +typedef enum X { ... } X; +``` +Back: The first `X` is a tag whereas the second is an alias for type `enum X`. +Reference: Van der Linden, Peter. _Expert C Programming: Deep C Secrets_. Programming Languages / C. Mountain View, Cal.: SunSoft Pr, 1994. + +END%% + +%%ANKI +Basic +What is the value of `A` in the following? +```c +enum X { A, B, C }; +``` +Back: `0` +Reference: Van der Linden, Peter. _Expert C Programming: Deep C Secrets_. Programming Languages / C. Mountain View, Cal.: SunSoft Pr, 1994. + +END%% + +%%ANKI +Basic +What is the value of `B` in the following? +```c +enum X { A, B, C }; +``` +Back: `1` +Reference: Van der Linden, Peter. _Expert C Programming: Deep C Secrets_. Programming Languages / C. Mountain View, Cal.: SunSoft Pr, 1994. + +END%% + +%%ANKI +Basic +What is the value of `B` in the following? +```c +enum X { A=2, B, C }; +``` +Back: `3` +Reference: Van der Linden, Peter. _Expert C Programming: Deep C Secrets_. Programming Languages / C. Mountain View, Cal.: SunSoft Pr, 1994. + +END%% + +%%ANKI +Basic +According to Linden, what is the "only advantage" of `enum`s over `#define`? +Back: `enum`s can usually be traced in a debugger. +Reference: Van der Linden, Peter. _Expert C Programming: Deep C Secrets_. Programming Languages / C. Mountain View, Cal.: SunSoft Pr, 1994. + +END%% + ## Bibliography -* Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016. -* Jens Gustedt, _Modern C_ (Shelter Island, NY: Manning Publications Co, 2020). +* “ISO: Programming Languages - C,” April 12, 2011, [https://port70.net/~nsz/c/c11/n1570.pdf](https://port70.net/~nsz/c/c11/n1570.pdf). +* Van der Linden, Peter. _Expert C Programming: Deep C Secrets_. Programming Languages / C. Mountain View, Cal.: SunSoft Pr, 1994.