When you compile a C program, the process involves several stages that transform the human-readable source code into machine-readable executable code.
- Preprocessing: The preprocessor handles directives like #include and #define. It expands macros and includes header files into the code, generating a modified source file.
- Compilation: The compiler converts the preprocessed C code into assembly language, performing syntax and semantic analysis. It checks for errors and translates the source code into an intermediate assembly code that the machine can understand.
- Assembly: The assembler converts the assembly code into object code, which is a binary format containing machine code but is not yet a complete program.
- Linking: The linker combines object files and libraries, resolving external references (like function calls) and producing an executable file. It ensures all functions and variables are correctly linked.
- Executable: The final output is a machine code file that can be executed directly by the computer’s operating system