Compare commits

...

17 Commits

Author SHA1 Message Date
zleyyij
6a21810c79 vault backup: 2024-11-10 22:11:06 2024-11-10 22:11:06 -07:00
zleyyij
d1232122ff vault backup: 2024-11-10 21:56:06 2024-11-10 21:56:06 -07:00
zleyyij
a1a7261269 vault backup: 2024-11-10 21:51:06 2024-11-10 21:51:06 -07:00
zleyyij
54375bff52 vault backup: 2024-11-10 21:46:06 2024-11-10 21:46:06 -07:00
zleyyij
71e73a9ef1 vault backup: 2024-11-10 21:41:06 2024-11-10 21:41:06 -07:00
zleyyij
d6f47d0f95 vault backup: 2024-11-10 21:36:06 2024-11-10 21:36:06 -07:00
zleyyij
a722cdd3b7 vault backup: 2024-11-10 21:31:06 2024-11-10 21:31:06 -07:00
zleyyij
a720c5d1f7 vault backup: 2024-11-10 21:26:06 2024-11-10 21:26:06 -07:00
zleyyij
b502602382 vault backup: 2024-11-10 21:21:06 2024-11-10 21:21:06 -07:00
zleyyij
5fee60ba7b vault backup: 2024-11-10 21:01:06 2024-11-10 21:01:06 -07:00
zleyyij
081dfe7116 vault backup: 2024-11-10 20:56:06 2024-11-10 20:56:06 -07:00
zleyyij
86ecc96c92 vault backup: 2024-11-10 20:51:05 2024-11-10 20:51:05 -07:00
zleyyij
2799f844b4 vault backup: 2024-11-10 20:46:05 2024-11-10 20:46:06 -07:00
zleyyij
21f55263c0 vault backup: 2024-11-10 20:41:05 2024-11-10 20:41:05 -07:00
zleyyij
6fc73295ae vault backup: 2024-11-10 20:36:05 2024-11-10 20:36:05 -07:00
zleyyij
669658b79e vault backup: 2024-11-10 20:31:05 2024-11-10 20:31:05 -07:00
zleyyij
2fdeda7c0a vault backup: 2024-11-10 20:21:05 2024-11-10 20:21:05 -07:00

View File

@ -0,0 +1,83 @@
> **1.** Section 15.1 listed several advantages of dividing a program into multiple source files.(a). Describe several other advantages
- Easier to scale horizontally as developers are added to the team
- Reduced cognitive load from less global scope to keep track of
> (b). Describe some disadvantages
- Increased complexity
- Need to maintain/troubleshoot a build system
---
> **2.** Which of the following should *not* be put in a header file? Why not?
b. Function definitions - Functions should only be defined once, and this allows multiple files to share the same function definition
---
> **3.** We saw that writing `#include <file>` instead of `#include "file"` may not work if file is one that we've written. Would there be any problem with writing `$include "file"` instead of `#include <file>` if *file* is a system header?
Yes, `""` is a path relative to the current file, whereas `<>` is a path to the system's standard library headers.
---
> **4.** Assume that `debug.h` is a header file with the following contents...
>(a). What is the output when the program is executed?
```
Output if DEBUG is defined:
Value of i: 1
Value of j: 2
Value of i + j: 3
Value of 2 * i + j - k: 1
```
> (b). What is the output if the `#define` directive is removed from `testdebug.c`?
```
Output if DEBUG is not defined:
```
> (c). Explain why the output is different in parts (a) and (b)
When `DEBUG` is defined, any instances of the `PRINT_DEBUG` token are replaced with a `printf` call during compile time, but when it's not defined, they're replaced with nothing.
> (d). Is it necessary for the `DEBUG` macro to be defined *before* `debug.h` is included in order for `PRINT_DEBUG` to have the desired effect? Justify your answer.
Macro invocations are evaluated sequentially, and so if `DEBUG` was defined after `PRINT_DEBUG`, then any usages of `PRINT_EVALUATION` would be have like `DEBUG` was not defined.
---
> **5.** Suppose that a program consists of three source files - `main.c`, `f1.c`, and `f2.c`- Plus two header files, `f1.h` and `f2.h`. All three source files include `f1.h` but only `f1.c` and `f2.c` include `f2.h`. Write a makefile for this program, assuming that the compiler is `gcc` and that the executable file is to be named `demo`.
```makefile
demo: main.o f1.o f2.o
gcc -o demo main.o f1.o f2.o
main.o: main.c f1.h
gcc -c main.c
f1.o: f1.c f1.h f2.h
gcc -c f1.c
f2.o: f2.c f2.h
gcc -c f2.c
```
---
> **6.** The following questions refer to the program described in Exercise 5.
> (a). Which files need to be compiled when the program is built for the first time?
`f1.c`, `f1.h`, `f2.c`, `f2.h`, `main.c`, `main.h`
> (b). If `f1.c` is changed after the program has been built, which files need to be recompiled?
Just `f1.c`.
> (c). If `f1.h` is changed after the program has been built, which files need to be recompiled?
All source files, because they all include `f1.h`.
> (d). If `f2.h` is changed after the program has been built, which files need to be recompiled?
`f1.c` and `f2.c`.