Notes on C

File extensions

OSExecutablesStatic librariesDynamic libraries
Linux.out.a.so
Windows.exe.lib.dll
macOS.out.a.dylib

Compilation pipeline

PhaseCommandInputOutput 
Preprocessinggcc -Esource code .ccompilation unit .i
Compilationgcc -Scompilation unit .iassembly code .s
Assemblegcc -cassembly code .srelocatable object file .o
Linkinggccrelocatable object file .oexecutable
// hello_world.c
#include <stdio.h>

int main(int argc, char const *argv[]){
    printf("Hello world");
    return 0;
}
gcc -E hello_world.c -o hello_world.i
gcc -S hello_world.i -o hello_world.s
gcc -c hello_world.s // generates hello_world.o
gcc hello_world.o // generates a.out

To execute each of the phases in the pipeline, gcc invokes different programs:

  • the preprocessor cpp
  • the assembler as
  • the linker ld

Process memory inspection

ps auwx | grep <pid>

Linux

cat /proc/<pid>/maps
sudo pmap -x <pid>

Apple

vmmap --wide <pid>