From d45d5ae14c0b50be5d615a9e9b883c0b0822e307 Mon Sep 17 00:00:00 2001 From: Jet Hughes Date: Mon, 5 Sep 2022 10:04:46 +1200 Subject: [PATCH] vault backup: 2022-09-05 10:04:46 --- content/notes/11-struct-and-union.md | 42 ++++++++++++++++++++++-- content/notes/12-pointers-to-routines.md | 10 ++++++ content/notes/cosc-204.md | 3 +- 3 files changed, 51 insertions(+), 4 deletions(-) create mode 100644 content/notes/12-pointers-to-routines.md diff --git a/content/notes/11-struct-and-union.md b/content/notes/11-struct-and-union.md index be1a21244..7eb68c81e 100644 --- a/content/notes/11-struct-and-union.md +++ b/content/notes/11-struct-and-union.md @@ -3,6 +3,10 @@ title: "11-struct-and-union" aliases: tags: - cosc204 +- lecture +sr-due: 2022-09-08 +sr-interval: 3 +sr-ease: 250 --- # Struct @@ -54,8 +58,8 @@ location.y = 1; copy the members including pointers - but not the things the pointers point to -![shallow copy example 1](https://i.imgur.com/w3B3ce0.png) -![shallow copy example 2](https://i.imgur.com/mL5QION.png) +![shallow copy example 1|200](https://i.imgur.com/w3B3ce0.png) +![shallow copy example 2|400](https://i.imgur.com/mL5QION.png) both point to the same memory location. when you change one - they both change. @@ -128,7 +132,39 @@ queue *queue_new(void){ ``` enqueue - ![enqueue code|400](https://i.imgur.com/suaKfi9.png) +dequeue +![dequeue code|400](https://i.imgur.com/u3mKX5R.png) + +# Structs as view +``` +typedef struct q_item { + int value; //4-byte integer + struct q_item *next; //8-byte pointer +} queue_item; +``` + +![](https://i.imgur.com/ObfIzew.png) + +struct is a view where the members are laid out consecutively + +# Union +multiple views of the same memory +- each line in the declaration is a different view + +``` +typedef union { + struct { + uint8_t a, b, c, d; + }; + uint32_t integer; +} two_views; +``` + +![diagram|100](https://i.imgur.com/qL8KnW5.png) + +## endianess +big-endian vs little-endian +some computer store the most significatn byte first, other store the least significant byte first diff --git a/content/notes/12-pointers-to-routines.md b/content/notes/12-pointers-to-routines.md new file mode 100644 index 000000000..a4934745a --- /dev/null +++ b/content/notes/12-pointers-to-routines.md @@ -0,0 +1,10 @@ +--- +title: "12-pointers-to-routines" +aliases: +tags: +- cosc204 +- lecture +--- + +# compiler +converts high level language description of program into machine code description of the program diff --git a/content/notes/cosc-204.md b/content/notes/cosc-204.md index 396af32f7..8deb9ab7d 100644 --- a/content/notes/cosc-204.md +++ b/content/notes/cosc-204.md @@ -38,7 +38,8 @@ tags: - [06-6809-programming](notes/06-6809-programming.md) - [07-6809-advanced](notes/07-6809-advanced.md) - [08-intro-to-c](notes/08-intro-to-c.md) -- +- [11-struct-and-union](notes/11-struct-and-union.md) + # Archive # Info