How the C++ Compiler Works

The Cherno · 976K views · 2017 · 17:55

Open on YouTube

C, C++, Rust, Go & systems languagesCompilers, interpreters & program analysistutorial

Why Stack Overflow recommends it

Stack Overflow users link it when explaining that only .cpp files are compiled and headers are just text included by the preprocessor, and when asking about compiler and linker behavior.

Recommended by 1 people across 1 different months, 2018 to 2020.

What it is

A 17-minute episode from The Cherno's C++ series that walks through what the compiler does with a source file: preprocessing, parsing, generating object files, and why only .cpp files are compiled. It uses live demos in Visual Studio, such as #define substitution and inspecting build output.

What people said

Recommends Rick · 2018-04 · Stack Overflow · on “Including .cpp files”

@pasha I used to read this answer and thought it was right too... It is so wrong and kinda misleading. There is no such "header file find .cpp file" thing. Because only .cpp files get compiled. Header files merely stay there and wait some source files to inlcude them. Check this video to learn more [this video]

Cites mya · 2020-04 · Stack Overflow · on “Visual studio the following code is built without any error?”

I have to link the video [this video] related, but I will also add the code below. How does this code builds without any error? #define INTEGER Cherno INTEGER Multiply(int a, int b){ INTEGER result = a * b; return result; } When he hits Ctrl+F7 and builds the code in visual studio, it builds without any error. What do I miss? Thanks. p.s : I know this code won't(at least should not) compile, I just wondered why it does in the case of the video owner.

Cites Josael Perez · 2020-09 · Stack Overflow · on “C++: How compiler and linker work when you have same function (static and non-static)?”

Let me explain what I want to understand, recently I see these videos from youtube about how the compiler and the linker work. How C++ works: [LINK] How C++ compiler works: [this video] How C++ linker works: [LINK] In those videos, it is explained what happens when you have functions with the same declaration and definition, but just have examples with static to static functions (that solves the linking error since each function is seen different) and non-static to non-static functions (which gives a linking error since the linker do not know what function are you calling). However, those videos are just extra information I will explain my doubt. Suppose we want to have to functions with the same