C is a general-purpose computer programming language. It was created in the 1970s by Dennis Ritchie, and remains very widely used and influential. By design, C's features cleanly reflect the capabilities of the targeted CPUs. It has found lasting use in operating systems, device drivers, and protocol stacks, but its use in application software has been decreasing. C is commonly used on computer architectures that range from the largest supercomputers to the smallest microcontrollers and embedded systems.
#include <stdio.h>
int main() {
printf("Hello, World!\n");
return 0;
}
-
gcc
is the GNU Compiler Collection, which can compile C, C++, Objective-C, Fortran, and Ada.to compile a C program:
gcc -o hello hello.c
-
g++
has additional behaviours in it specific to c++, such that it can compile and link a c++ program out of the box to compile a C program:g++ -o hello hello.c
-
llvm
is a collection of modular and reusable compiler and toolchain technologies.to compile a C program:
llvm-gcc -o hello hello.c
-
clang
is a C, C++, and Objective-C compiler which encompasses preprocessing, parsing, optimization, code generation, assembly, and linking.to compile a C program:
clang -o hello hello.c
Compilation process in C involves four steps:
graph LR;
subgraph Linking
D1["Object code (.o)"] --> D2["Linker"];
D2 --> D3["Executable file"];
end
subgraph Assembling
C1["Assembly code (.s)"] --> C2["Assembler"];
C2 --> C3["Object code (.o)"];
end
subgraph Compiling
B1["Modified source code (.i)"] --> B2["Compiler"];
B2 --> B3["Assembly code (.s)"];
end
subgraph Preprocessing
A1["Source code (.c)"] --> A2["Preprocessor"];
A2 --> A3["Modified source code (.i)"];
end
A3 --> B1;
B3 --> C1;
C3 --> D1;
-
Preprocessing: The preprocessor takes the source code and eliminates comments, expands macros, and includes header files. The output of this step is a
.i
file. -
Compiling: The compiler takes the preprocessed file and converts it into an assembly code file. The output of this step is a
.s
file. -
Assembling: The assembler takes the assembly code file and converts it into an object code file. The output of this step is a
.o
file. -
Linking: The linker takes the object code file and links it with other object code files and libraries to create an executable file.