A C interpreter project has eight source files: main.c, parse.c, eval.c, print.c, io.c, mem.c, hash.c and log.c. The header types.h contains the line #include "config.h". The files parse.c, eval.c and print.c include types.h, and the files main.c, eval.c and log.c include config.h directly. No other file includes either header. Compiling one source file takes 1.8 s on average, and linking takes 0.9 s. Assume compilations run sequentially, followed by one link, and ignore all other overhead. After you edit config.h, find the number of source files that must be recompiled. Also estimate the rebuild time in seconds, including the link, to one decimal place, and the time saved compared with a full build, in seconds to one decimal place.
Unlock full course notes by signing up
Diagnosing an undefined reference
A project has two source files. main.c includes stats.h, which declares double mean(const double *x, int n);, and main.c calls mean. The file stats.c defines mean. A student builds with these commands:
The first two commands succeed without warnings, but the third prints undefined reference to 'mean'. Which explanation and fix is correct?
A macro defined with a zero value
A developer uses the following C source to control which initializers reach the compiler. No command-line options or other source lines change the macro definition.
Complete these statements using decimal integers: after preprocessing, the initializer for retained is ________, and the initializer for level is ________.
Which archive members enter the link?
A C project links ordinary object files with a static archive, a collection of object files from which the linker can extract individual members. Use this linker model:
Process inputs from left to right. Always include an ordinary object file, recording its definitions and unresolved references.
When an archive is reached, extract a member if it defines a currently unresolved symbol. Record that member's definitions and references, then continue searching the same archive until no further member is needed.
Parallel compilation and the final link
A developer measures a clean build of a C program. Compiling sensor.c, filter.c, stats.c, and format.c takes exactly 9 s, 7 s, 5 s, and 3 s, respectively. The four compilations are independent. Linking their object files takes exactly 2 s and starts immediately after all four compilations finish.
Compare two identical build machines, one allowing two compilation jobs at once and the other allowing three. Both use this scheduling rule: at time zero, start as many jobs as possible from the queue sensor.c, filter.c, stats.c, format.c; whenever a slot becomes free, immediately start the next waiting job. Each job occupies one slot until it finishes.
Assume that the stated durations remain unchanged when jobs overlap, and ignore other overhead. Determine: