COP 3223H meeting -*- Outline -*- * Compilation with multiple modules in C ** typical homework problem example ------------------------------------------ TYPICAL HOMEWORK PROBLEM MODULES Suppose you are to write function f. We provide all files except f.c (where you put the code for f) Modules: tap.c with header tap.h f.c with header f.h test_f.c Compilation command: gcc -Wall -pedantic tap.c f.c test_f.c -o test_f Compilation works in stages: 1. compiling each module (gcc -c *.c) tap.c -> tap.o f.c -> f.o test_f.c -> test_f.o 2. loading/linking (gcc *.o -o test_f) tap.o f.o test_f.o -> test_f.exe During step 1 the compiler During step 2 the loader/linker Running the program: > ./test_f runs test_f.exe on Windows test_f on Unix/MacOS ------------------------------------------ ... checks each individual file (type checking, etc.) ... checks consistency between all cross references among files (also a kind of type checking) ** declarations and scope issues ------------------------------------------ DECLARATIONS AND SCOPE FOR FUNCTIONS in C A function declaration extern double f(int x); A function declaration and definition double f(int x) { return x*2.0; } Scope of a declaration extends ------------------------------------------ from the point of declaration through the rest of the block/file in which the declaration occurs