Four stages. The preprocessor expands #includes, macros, and conditional-compilation directives into a single block of pure C text. The compiler parses and type-checks that text, runs optimizations, and emits assembly for the target architecture. The assembler turns the assembly into a machine-code object file (.o) containing sections like .text, .data, .bss, plus a symbol table of what it defines and what it references. Finally the linker combines all object files and libraries, resolves every external symbol reference to a definition, lays out the sections, and produces the executable. Each .c is compiled independently as a translation unit, which is why the linker exists, to connect them.
C Programming · Interview question
Walk me through what happens when you compile a C program.
A strong answer
What a weak answer sounds like
You know the answer. Do you know what gets you dinged?
Pro breaks down the answer most candidates actually give to this question — and the specific reason an interviewer marks it down. It’s the difference between sounding correct and sounding senior, on all 472 questions.
From the lesson
The C Compilation Pipeline
What gcc actually does between your .c file and a flashable binary, and why 'undefined reference' and 'implicit declaration' are different bugs at different stages.
More The C Compilation Pipeline questions
What's the difference between a declaration and a definition?You get "undefined reference to uart_init". What stage failed and what are the likely causes?Why does changing one header file trigger a rebuild of many source files?On an embedded target, what extra build steps exist beyond a desktop compile, and why?
Browse all 472 interview questions