Drills: check yourself
Answer on your own first, and only then open the answer.
1. Who wrote this message, and what do you check?
ld.exe: main.c:(.text+0x80): undefined reference to `average'
Answer
The linker (ld): main.c compiled, but there's no definition of average. Check that the .c file with average is in the target's list in CMakeLists.txt (or that the program is linked with the library), and that the function really is written with that same name.
2. Which lines belong in a .h file?
double average(const int grades[], int count);
#define MAX_GRADES 30
static int nearly_equal(double a, double b) { return a - b < 0.001 && b - a < 0.001; }
int count = 0;
Answer
The first two: a declaration and a constant. A static function with a body belongs in a .c file, and a variable in a .h file, included into two .c files, would cause multiple definition.
3. What happens? main.c starts with #include "daytime.c", and CMakeLists.txt has add_executable(p07_duration main.c daytime.c).
Answer
A linker error, multiple definition: the functions of daytime.c are pasted into main.c and compiled once more from daytime.c. .c files aren't included: daytime.h is.
4. Two files, a.c and b.c, each have their own helper int helper(void) (with different bodies), and neither is in a .h file. The program doesn't build. Why, and how do you fix it?
Answer
Without static both functions are visible to the whole program, and the linker finds two definitions of helper: multiple definition. The fix is static int helper(void) in both files: then each is visible only in its own file.
5. An old comment line says "Before: count >= 1." Which Doxygen tag do you write it with?
Answer
@pre count >= 1. "After:" becomes @return when it's about the returned value.