Foundations: The Machine Model

an executable

When you compile a C program, you get a single file you can launch to make the program run. That file is an executable: a self-contained bundle of machine code plus the bits of information the operating system needs to load it into memory and start it going. It is the program in its ready-to-run form, as opposed to the source text you wrote.

An executable is more than a raw dump of machine code. It is a structured file in a particular format (ELF on Linux, Mach-O on macOS, PE on Windows) with sections: the code (instructions), initial data (preset values), space reserved for variables, a table saying where execution should begin, and metadata. When you launch it, the operating system's loader reads this file, copies the relevant parts into memory, sets up the starting state, and points the CPU at the entry point so the fetch-execute cycle can begin. On Unix you typically run it as ./prog.

Why it matters: the executable is the concrete deliverable of compilation - the thing you ship and run, not your source. Because it contains machine code for one CPU family and expects a particular operating system, an executable built on one platform usually will not run on a very different one without rebuilding from source. Understanding what is inside an executable also opens the door to crucial systems topics: how programs are laid out in memory, how they link to libraries, and how debuggers and tools inspect them.

After gcc hello.c -o hello, the file 'hello' is your executable. Running file hello on Linux reports something like 'ELF 64-bit executable' - the OS knows how to load and start it; a plain text editor would just show gibberish bytes.

The compiled, ready-to-run artifact - structured machine code, not readable text.

An executable is not portable across very different machines: it holds machine code for one CPU type and assumes one OS. Source code is the portable thing; you re-compile it per target to get a new executable. (How linking and loading work in detail comes later.)

Also called
executable filebinaryprogram file二進位檔執行檔