28 lines
1.2 KiB
Markdown
28 lines
1.2 KiB
Markdown
# Memory layout
|
|
|
|
The questions are on Canvas. This folder has the three small programs you measure with and the file you write your answers in.
|
|
|
|
| File | What it is |
|
|
| :--- | :--- |
|
|
| layout.c | struct A and struct B; print their sizes and offsets (questions 1 to 3) |
|
|
| shrink.c | struct C in two orders; print both sizes (question 4) |
|
|
| node.c | struct Node; print its size and where next is (question 5) |
|
|
|
|
## Build and run
|
|
|
|
Each C file's top comment has its build command, for example:
|
|
|
|
gcc -std=c99 -pedantic -Wall -Wextra -o layout layout.c
|
|
./layout
|
|
|
|
Then run the self-check from this folder:
|
|
|
|
python3 selfcheck.py
|
|
|
|
It needs Python 3 and gcc or clang. It checks that each program builds, prints its labels and that HW12.md has no "(write here)" left. A pass means everything is there, not that every number or explanation is right. If a tool gets in your way, keep what you measured and ask in class or office hours.
|
|
|
|
## Help
|
|
|
|
- Beej's Guide to C, structs II: <https://beej.us/guide/bgc/html/split/structs-ii-more-fun-with-structs.html>
|
|
- offsetof on cppreference: <https://en.cppreference.com/w/c/types/offsetof>
|
|
- Alignment on cppreference: <https://en.cppreference.com/w/c/language/object#Alignment>
|