mirror of
https://github.com/jackyzha0/quartz.git
synced 2025-12-27 14:54:05 -06:00
vault backup: 2022-09-05 10:04:46
This commit is contained in:
parent
1c4a02c83c
commit
d45d5ae14c
@ -3,6 +3,10 @@ title: "11-struct-and-union"
|
|||||||
aliases:
|
aliases:
|
||||||
tags:
|
tags:
|
||||||
- cosc204
|
- cosc204
|
||||||
|
- lecture
|
||||||
|
sr-due: 2022-09-08
|
||||||
|
sr-interval: 3
|
||||||
|
sr-ease: 250
|
||||||
---
|
---
|
||||||
|
|
||||||
# Struct
|
# Struct
|
||||||
@ -54,8 +58,8 @@ location.y = 1;
|
|||||||
copy the members including pointers
|
copy the members including pointers
|
||||||
- but not the things the pointers point to
|
- but not the things the pointers point to
|
||||||
|
|
||||||

|

|
||||||

|

|
||||||
|
|
||||||
both point to the same memory location.
|
both point to the same memory location.
|
||||||
when you change one - they both change.
|
when you change one - they both change.
|
||||||
@ -128,7 +132,39 @@ queue *queue_new(void){
|
|||||||
```
|
```
|
||||||
|
|
||||||
enqueue
|
enqueue
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
dequeue
|
||||||
|

|
||||||
|
|
||||||
|
# Structs as view
|
||||||
|
```
|
||||||
|
typedef struct q_item {
|
||||||
|
int value; //4-byte integer
|
||||||
|
struct q_item *next; //8-byte pointer
|
||||||
|
} queue_item;
|
||||||
|
```
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
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;
|
||||||
|
```
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## endianess
|
||||||
|
big-endian vs little-endian
|
||||||
|
some computer store the most significatn byte first, other store the least significant byte first
|
||||||
|
|
||||||
|
|||||||
10
content/notes/12-pointers-to-routines.md
Normal file
10
content/notes/12-pointers-to-routines.md
Normal file
@ -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
|
||||||
@ -38,7 +38,8 @@ tags:
|
|||||||
- [06-6809-programming](notes/06-6809-programming.md)
|
- [06-6809-programming](notes/06-6809-programming.md)
|
||||||
- [07-6809-advanced](notes/07-6809-advanced.md)
|
- [07-6809-advanced](notes/07-6809-advanced.md)
|
||||||
- [08-intro-to-c](notes/08-intro-to-c.md)
|
- [08-intro-to-c](notes/08-intro-to-c.md)
|
||||||
-
|
- [11-struct-and-union](notes/11-struct-and-union.md)
|
||||||
|
|
||||||
# Archive
|
# Archive
|
||||||
|
|
||||||
# Info
|
# Info
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user