"But we're not talking about Linking. The video about that is in the description" >Clicks "So the first stage is actually compiling, I made an entire video about that.. Link is in the video description" WARNING: Infinite Loop Detected
Guys he obviously doesn't need to know how the compiler works while writting code at his job, yeah it's nice an interesting to know, he pointed that out. Shaming him is nonsense.
I'm super late to the party but screw it, this was hands down the best C++ video I have ever seen, full stop. It might be the best tutorial I've ever seen. Not only are you engaging and interesting to listen to, but you make the concepts really easy to understand without oversimplifying or dropping necessary information. This should be mandatory viewing for anyone learning C++. How none of this was ever covered in my entire 4 year Computer Engineering program is beyond me.
Agreed. I am in the early courses of computer science right now and this has been more helpful than my textbooks/lectures. I look forward to going through the rest of the series
@@YmanUA-cam It mostly depends on what you want to do. Both will cover the basics; fundamental coding practices, algorithms and data structures, but they focus on different areas. CS is more about higher level concepts and pure software design including web development, machine learning/AI, and data science. CE is more low level, most CE degrees include electrical engineering elements and they focus a lot on computer architecture, digital design, and imbedded systems, a lot of C and C++. So if really depends on what you might want to do with your career. Bare in mind of course that's based on my experience, you should always look at what the programs at your school looks like.
Best C++ series ever. I'm actuallty a very experienced C programmer, and have started diving into C++ recently. These videos are just really good. Thanks for the good work!
I have been programming for a while too, I think these videos are great. I can't judge if they are perfect for beginners, but I pick up a lot of helpful stuff.
Cherno is very good, but I have also found a few others that you can check out... You can look at Jason Turner's, Javidx9's {OneLoneCoder}, and Bisqwit's channels. A little bit different but Ben Eater explains Computer Science and Computer Engineering very well too, and for any advanced math topics, 3Blue1Brown. I have found these to be some of my favorite channels. Also for C++ if you want an in-depth explanation of the most commonly used std library classes, containers and algorithms check out Bo Qian. For course study, Standford and MIT have great online videos of their courses... There are a few others that I like but they are specialized as they work with APIs such as Direct X, OpenGL, and Vulkan... Other channels pertain to hardware design directly and the process of designing an Instruction Set, Assembler and Assembly language for a custom CPU and its ISA (Instructure Set Architecture). Such as Bilkent Online Courses for their CS-224 course.
I'm on my 3rd year of a computer science degree and I feel like I learned more from your videos than I did in my first 2 years. Absolutely brilliant content, pacing and delivery. I started with Java and touched on other high level languages like C#. I was really weary about moving to C++ as most videos go from the absolute basics of coding so it's difficult to find what you need. This series on the other hand delivered EXACTLY what I was after. So glad I found you. Thank you!
summary: Compilation is the process where we convert our plain text of the cpp files into a machine code that is readable by the CPU. It occurs in several steps. The first step is 'preprocessing', which evaluates the proprocess statements. This is followed up py tokenizing, parsing and so on, which will create an abstract data tree(?). In cpp, files have no meaning, and this is to be compared with Javascript. The cpp compiler by default treats .h, .cpp files as the way they are, but we can specifically direct the compiler to treat any random file like any other random file. Therefore, we can just make a .cherno file, and make the compiler treat it like a cpp file. //To be honest, I didn't really get what he meant here. Going over the preprocessing statements, the most common statements are #include, #define, #prgma(?) and so on. #include basically results in the computer to find the file with that name and copy and paste its content into the current file. #define is followed by 2 arguments, and will replace all of the first argument found in the text into the second argument. To see what is going on during the preprocessing stage, we can change the property of our exe file so that it preprocesses to a file, and open the .i file with an text editor. After the preprocessing stage and a series of subsequent stages(cherno didn't cover obout these stages in these video), the compiler results in an obj file. Opening this in an text editor will show hexadecimal looking numbers, which we cannot understand. So we can manipulate the property of the project, click c/c++ --> output files --> assembly output, and change the option from no listing to assembly only listing. Compiling the file after this settings will result in a .asm file being created ind the debug folder, together with the other obj files. This is the readable format of the machine code, and Cherno uses this file to demonstrate how optimization option runs our code faster by reducing redundancy. So in our properties, we can enable optimation, which also requires to change the code generation-> basic runtime check should also be set to default. Cherno makes a 'log' function that returns the message that it receives, and *for no reason*, puts it in the middle of the 'multiply' function he created. Without the optimization, we can see in the .asm file that the compiler calls for the 'log'function for no reason, which slows down the computer by adding additional line to the code. With the optimization turned on and compiling the file again, the whole line that calls for the redundant 'log' line is just gone, because the compiler decides to delete the whole section since it understands that it is unnecessary.
The .cherno thing he meant by it that the compiler will treat your file like any text file so you don't to name it by .cpp extension. Infact you can compiler any text file that have cpp code in it
if abject file does not contain the call to message/ print message then how will our application print the message at the end of the day, that isn't optimization its data loss
Dude, this series is amazing, seriously! I come with a bit of background of assembly, c++, c# and python and you explain things so well! Thank you very much for these videos :)
Fuck men, I've been watching him for over a year now, and never noticed it, then came here to read comments, and now i can't unhear it anymore, can't focus on words coming from his mouth. Burn in hell!!!!!!!!!
@@geronimo9824 It's probably because Rohit must be close enough to music instruments so that his sensitivity already gets more about sounds faster than you do. I'm a musician myself and one of the first stuff I noticed was the great tracks Cherno uses as bg sound.
Okay man seriously your C++ tutorials are the best programming tutorials in any language I've ever coded in. It feels so good, even if it's only scratching the surface, getting a good understanding of the underlying nuts and bolts of every line of code. Thank you very much!
Been programming c++ for just under a year now, consistently. It's amazing how I still learn new things everyday, especially from you. Thanks so much, man. I appreciate it so much.
I found your channel and I am thrilled. I wish I could freeze time for anything but me, my computer, my internet connection and UA-cam servers in order to just get all this information in no time.
Super cool to see how the C++ code gets turned into Assembly and Machine Code, and also really helpful to have a better understanding of what the compiler is actually doing!
Playing around like this is the absolute best way to learn the internals of programming. Not merely watching videos, but actually DOING the work. Now go play!!! 😁
I'm only a few videos in and it's such a breath of fresh air to find someone who knows their topic well enough to explain it in such easy terms. Preprocessing itself has been so badly explained to me by teachers at all levels and udemy 'instructors' and then here you go and show me that it's perhaps one of the simplest things you can imagine. Thank you. Thank you for the effort you've made in creating this.
Great videos, thank you so much. I have been watching your videos. For brief notes, i asked gpt "How the C++ Compiler Works": The C++ compiler transforms C++ source code into executable machine code through several stages. Understanding these stages can help you write more efficient and error-free code. Here’s an overview of how the C++ compiler works: ### 1. **Preprocessing** - **Input:** Source code files (`.cpp`, `.h`). - **Output:** Preprocessed source code. - **Actions:** - **Macro Expansion:** Expands all macros defined with `#define`. - **File Inclusion:** Inserts the content of the included header files (`#include` directives). - **Conditional Compilation:** Evaluates `#if`, `#ifdef`, `#ifndef`, and similar directives to include or exclude parts of the code. - **Removing Comments:** Strips out comments from the source code. ### 2. **Compilation** - **Input:** Preprocessed source code. - **Output:** Assembly code. - **Actions:** - **Syntax Analysis (Parsing):** Checks the code for syntactical correctness. Converts the code into an Abstract Syntax Tree (AST). - **Semantic Analysis:** Ensures the code adheres to the language rules and checks for semantic errors (e.g., type checking, variable declarations). - **Intermediate Code Generation:** Converts the AST into an intermediate representation (IR). - **Optimization:** Performs various optimizations on the IR to improve performance and reduce the code size. - **Code Generation:** Translates the optimized IR into assembly code for the target architecture. ### 3. **Assembly** - **Input:** Assembly code. - **Output:** Object code (machine code). - **Actions:** - Converts the human-readable assembly code into machine code instructions specific to the target CPU architecture. - Produces an object file (`.o` or `.obj`), which contains the machine code and additional information like symbol tables and relocation information. ### 4. **Linking** - **Input:** Object code files and libraries. - **Output:** Executable file. - **Actions:** - **Symbol Resolution:** Resolves references to functions and variables across different object files. - **Relocation:** Adjusts addresses within the code and data sections. - **Library Linking:** Includes necessary code from static libraries (`.lib` or `.a`) or dynamic/shared libraries (`.dll` or `.so`). - Produces the final executable file that can be run on the target system. ### 5. **Loading (Execution Time)** - **Input:** Executable file. - **Output:** Running process. - **Actions:** - The operating system loads the executable into memory. - Allocates memory for the program’s stack, heap, and data segments. - Resolves dynamic library references (if any). - Transfers control to the program’s entry point (usually the `main` function). ### Additional Details - **Error Handling:** At each stage, the compiler checks for errors and warnings, providing feedback to the programmer. - **Debugging Information:** The compiler can include debugging information in the object files to help with debugging. - **Optimization Levels:** Compilers often offer various optimization levels (e.g., `-O1`, `-O2`, `-O3` in GCC) to control the trade-off between compilation time and the performance of the generated code. ### Example of a Compilation Process For a file `main.cpp`, the typical compilation process using a command-line tool like `g++` might look like this: ```sh g++ -o main main.cpp ``` This command tells the `g++` compiler to preprocess, compile, assemble, and link `main.cpp` into an executable named `main`. By breaking down the compilation process into these stages, you can better understand how your C++ code is transformed into a running program and optimize or debug each part of the process effectively.
Usually when I work through video courses, I'll watch them at 1.5-2 x speed. When I see the total number of hours, I also factor the speed shift in and determine how much value a course has. Anywayz...none of that applies here :D I've worked through a number of C++ courses, but I can't resist starting from scratch with this series as I've already come across more than I had previously known. While most kids got a teddy-bear as their first gift, I'm sure you were given a laptop and a copy of Programming Principles and Practice Using C++ by Bjarne Stroustrup. No wonder EA are cranking out some amazing titles. I'm sure I'm not alone in saying that I really appreciate your effort and I'll be sure to contribute when I can. Cheers!
lmaooo 7:33 who would've thought that these things can be that much simple like i was amazed that you can just create any header file and write #include and it will just paste that thing lmao man, you are great at explaining things, i love you
Thanks for the great instruction. It is so much easier to understand by watching you going through the demonstration. I think at 11:43 it is the hexadecimal (0-F) representation. The assembly code is useful to debug some weird and tough bug. I also watched your video about the linking. It was very helpful too.
Dude, I have gone through so many c++ series and almost all of them are either garbage or redundant. Your series is a pure gem. It will help me to grow my embedded systems skills. Cheers!
00:00 - 10:02 The video discusses how the C++ compiler works, focusing on the compiling stage The compiler's main task is to convert C++ code into an object file It goes through pre-processing, tokenizing, and parsing stages to create an abstract syntax tree The compiler then generates machine code for the CPU to execute Each CPP file in a project results in a translation unit and object file Preprocessor statements like include, define, and if are explained and demonstrated The video provides a simple example of a multiply function and shows the pre-processed code The process of including header files and using preprocessor statements is demonstrated in the video 09:56 - 17:45 The video discusses the preprocessor in C++ and demonstrates how to disable and enable certain code sections It also explains how to compile C++ code into machine code and optimize it for speed The video shows how constant folding works and how the compiler generates machine code for function calls The importance of understanding the C++ compiler for debugging and advanced topics is emphasized
Absolutely loving the series so far. Great job! Will you ever cover how to compile into DLL files and then use them as references in different projects?
DLLs are just like regular static libraries except you need the DLL next to the exe and you must export your functions to the DLL. Im sure Cherno will go in depth of this.
I didn't find any person like you to explain in the simplest possible way. I saw an everyday video about programming for 10 years but I never find a person to explain this detail. It's absolutely easy for me because I had experience in programming but if someone new to programming with your video learns readily.
I've just started with operating system development at my university (TU Dortmund - Germany) and missed out this whole compilation part (preprocessing, compilation, assembling, linking). This video helped me out a lot. Thanks for that - you've earned yourself a new subscriber! Edit: The quality of your education video is also top notch! Simple, in depth, no annoying background music, good examples. Keep it up!
Once again, thank you for these videos, Cherno, but the music is very distracting. It might not be for you, but for a beginner trying to process all this new information while following the video, it certainly is. I really do appreciate this, don't get me wrong.
This is perfect. I am a software developer but do not have a formal cs degree, and this series has laid a solid foundation on stuff I had no clue how worked. Thanks
Visual comparison of before and after optimization powerfully illustrates what compilation does. I appreciate this level of detail and approach to explanation.
"C++ is text. That's it. It's just a text file." me: *having existential crysis* EDIT: this was so pleasant to listen to like a cooking instruction. You really got it down man!
Wow, your explanation of header files was incredibly good and simple. As a beginner I kept seeing how header files were used, but not how they worked. Good job!
For Mac OS users using XCode: - Getting the Preprocessor file : Editor > Assistant > Click on Counterparts > Select Preprocessor - Getting the Assembly file : Editor > Assistant > Click on Counterparts > Select Assembly
As C compiler optimizes and compiles code in to an executable. You too have compiled lot of information in to a short and precise video. You cleared lot of myths I had in my mind for this compiling process. Thanks a lot.
This is fantastic. I have been programming for a couple months now and this cleared the water for so many things I was having trouble understanding. Thank you.
Whoever doesn't like your videos, need to get a grip. You killin the game, The Cherno! Very articulate and concise explanations and code examples for anyone who isn't familiar with how it all works. I am 24 years in the game and I am hard to impress. You did that! Props!
I've started watching your videos 3 years ago to learn C++ and just came back for basic knowledge and how C++ works in general under the hood and WOW, never expected to gain so much information again from these what I called "boring" videos.
Slight constructive feedback. Blink more. You seem to have done jump cuts to make it flow better (which is great) but you also appear to not blink at all during the intro thanks to it. It's noticeable which makes it distracting (and sorta creepy). So yeah, just try to blink normally even though its weird with lights/camera and stuff.
Yeah, people tend to notice if someone talking to them is blinking too often or not often enough. Since you have bright lights in your eyes in a situation like this you tend to blink too often so you have to consciously avoid doing that, aaaand then you might go the opposite direction. It's not a big deal, but worth thinking of when recording videos.
Interesting, but personally I don't care much about that. Though now it would be awkward if he started to blink more often now that I know that. See what you have done to my mind?
idk why people complaining for high quality free content. i get some people are really advanced, but I think even though I do speak c++ to put it that way, it's a nice refresher as well as it is a complete series from begin to end. if he does finish it.
I remember seeing this series few years ago and thinking that the channel deserves to be way more popular... And now in 2020: 335K subs, glad you've made it! :)
By far the best video I have ever seen on this topic. Clear, concise, on-topic, with a lot of enlightening examples and with some very interesting background information. Congratulation!
10 years into fullstack web app, mobile and software programming, I wanted to learn C++ so I can create faster backends and create desktop app/games. This is the only tutorial that explained perfectly how C++ works
Well you can get that the quality of the video is high from the astonishing rate of people truly satisfied in the comments below.. You are doing an amazing job here explaining also the background, it makes much more sense when things have a deeper reason. Thank you very much man!
Cherno, you are a brilliant teacher! Thank you so much. You explain things so clearly! Please keep up this great work. I only started learning C++ today. Have been a web dev for 14 years, but want to dive into game programming. Your tuts are my go-to :)
Darn, I have to say, this tut is really impressive. I like your information density and how you present said information. I just started the tut and I'm really looking forward to the rest of the videos in this playlist :D Thanks and have a good one
It must have took quite some effort for making such content for free. Evergreen content. Till C++ stays, this content remains relevant. Hats off Cherno! Thanks for these gem videos!
Fantastically explained. Been programming for a few years now, but never really jumped into CPP. Really good explanation of some of the things that go on when i hit that 'Build' button.
Wow i have been working with c++ and programming languages in general for a couple years now , but gotta say these tutorials are really good easy to understand , keep the good work Mate
I am happy to be here again Cherno, this time I will follow until the end. Just one note to add: 11:20 that's not binary, that's machine code; and object file can have an extension .obj (windows) or .o (linx) it depends on which compiler you use. I remember this video and seeing you doing those intermediate steps / outputs was amazing. Thank you very much. Best subscription in 10+ years Oh my bad.. it is binary but with hexadecimal notation.. now I am confused I always thought that machine code and assembly were different things... i should remove this comment beforr someone quit 😄
Thank you for this series!!! You cover alot of stuff that has been a mystery to me....you explain C++ much more in depth than most people....you should charge for this content....your taking all the mystery out of C++ and making it look easy.
Wow, I am amazed by the content provided by this channel. Really thank you very much TheChernoProject! Seriously learning more from this free video series than my C++ class in school.
I came here thinking it'll be a beginner course, but you have a talent to mix beginner and advenced notions, i think your videos are perfect for anyone who tries to learn or perfect their Cpp skills, truly anyone can learn something here, that's a video quality i've not seen very often, best cpp course out here imo (sry for my broken english, not native speaker and my last english class is getting a bit old ^^)
I've just started the series but thank you so very much. ❤️ I got 1,5 months to get sure on C++ (I've gone through the basics before, but your explanations are somehow catchy) and learn to work with Unreal engine. You're saving me tons of time I don't have. 😄
"But we're not talking about Linking. The video about that is in the description"
>Clicks
"So the first stage is actually compiling, I made an entire video about that.. Link is in the video description"
WARNING: Infinite Loop Detected
Deadlock found!
You clearly need a break here...
It's very recursive...
#ifndef _linking_video_H_
*link to video*
#endif
#pragma once
I've been programming for 20 years, and I actually learned something new here. Thanks!
That sounds pathetic, to be honest.
so many years taken
You should feel really bad about yourself making money out of something you're not professional enough
Hold on, we have a badass over here xD
Guys he obviously doesn't need to know how the compiler works while writting code at his job, yeah it's nice an interesting to know, he pointed that out. Shaming him is nonsense.
I'm super late to the party but screw it, this was hands down the best C++ video I have ever seen, full stop. It might be the best tutorial I've ever seen. Not only are you engaging and interesting to listen to, but you make the concepts really easy to understand without oversimplifying or dropping necessary information.
This should be mandatory viewing for anyone learning C++. How none of this was ever covered in my entire 4 year Computer Engineering program is beyond me.
agreed. Only thing a bit bothering is the background music. If it was at least a bit lower volume.
Agreed. I am in the early courses of computer science right now and this has been more helpful than my textbooks/lectures. I look forward to going through the rest of the series
Agreed. I've tried various books and video courses, and every time I end up thinking "Cherno's videos are better"
would you recommend getting a CS or a CE degree?
@@YmanUA-cam It mostly depends on what you want to do. Both will cover the basics; fundamental coding practices, algorithms and data structures, but they focus on different areas. CS is more about higher level concepts and pure software design including web development, machine learning/AI, and data science. CE is more low level, most CE degrees include electrical engineering elements and they focus a lot on computer architecture, digital design, and imbedded systems, a lot of C and C++. So if really depends on what you might want to do with your career.
Bare in mind of course that's based on my experience, you should always look at what the programs at your school looks like.
Best C++ series ever. I'm actuallty a very experienced C programmer, and have started diving into C++ recently. These videos are just really good. Thanks for the good work!
I have been programming for a while too, I think these videos are great. I can't judge if they are perfect for beginners, but I pick up a lot of helpful stuff.
shouldn't be taking effort cause syntax is 80% the same right?
Awhile ago you could probably get away with saying C++ is just C with OOP. These days that just isn't true. C++ is much more than that.
Trying to master C++ for five years. You are the first person that makes sense!
how much progress have you made yet?
@@Skulltroxx Watch Mr. Hendricks life story in Silicon Valley 😉
Cherno is very good, but I have also found a few others that you can check out...
You can look at Jason Turner's, Javidx9's {OneLoneCoder}, and Bisqwit's channels.
A little bit different but Ben Eater explains Computer Science and Computer Engineering very well too, and for any advanced math topics, 3Blue1Brown.
I have found these to be some of my favorite channels. Also for C++ if you want an in-depth explanation of the most commonly used std library classes, containers and algorithms check out Bo Qian.
For course study, Standford and MIT have great online videos of their courses...
There are a few others that I like but they are specialized as they work with APIs such as Direct X, OpenGL, and Vulkan...
Other channels pertain to hardware design directly and the process of designing an Instruction Set, Assembler and Assembly language for a custom CPU and its ISA (Instructure Set Architecture). Such as Bilkent Online Courses for their CS-224 course.
@@skilz8098 so much value from one comment thank you very much, may the force be with you
@@skilz8098 Bisqwit is life.
All my .cpp files are gonna be .cherno files now
LMAO
@@michaelpacheco7421 I find it so funny that any normal person would be like "WTF even are you talking about?". >D
That chernobryl ransomware
@@muthukumarp9934
Cherno is not q ransomware
@@codehorse8843 are you supposing we are not normal?
I'm on my 3rd year of a computer science degree and I feel like I learned more from your videos than I did in my first 2 years. Absolutely brilliant content, pacing and delivery. I started with Java and touched on other high level languages like C#. I was really weary about moving to C++ as most videos go from the absolute basics of coding so it's difficult to find what you need. This series on the other hand delivered EXACTLY what I was after. So glad I found you. Thank you!
summary:
Compilation is the process where we convert our plain text of the cpp files into a machine code that is readable by the CPU.
It occurs in several steps. The first step is 'preprocessing', which evaluates the proprocess statements. This is followed up py tokenizing, parsing and so on, which will create an abstract data tree(?).
In cpp, files have no meaning, and this is to be compared with Javascript. The cpp compiler by default treats .h, .cpp files as the way they are, but we can specifically direct the compiler to treat any random file like any other random file. Therefore, we can just make a .cherno file, and make the compiler treat it like a cpp file.
//To be honest, I didn't really get what he meant here.
Going over the preprocessing statements, the most common statements are #include, #define, #prgma(?) and so on.
#include basically results in the computer to find the file with that name and copy and paste its content into the current file.
#define is followed by 2 arguments, and will replace all of the first argument found in the text into the second argument. To see what is going on during the preprocessing stage, we can change the property of our exe file so that it preprocesses to a file, and open the .i file with an text editor.
After the preprocessing stage and a series of subsequent stages(cherno didn't cover obout these stages in these video), the compiler results in an obj file. Opening this in an text editor will show hexadecimal looking numbers, which we cannot understand. So we can manipulate the property of the project, click c/c++ --> output files --> assembly output, and change the option from no listing to assembly only listing. Compiling the file after this settings will result in a .asm file being created ind the debug folder, together with the other obj files. This is the readable format of the machine code, and Cherno uses this file to demonstrate how optimization option runs our code faster by reducing redundancy.
So in our properties, we can enable optimation, which also requires to change the code generation-> basic runtime check should also be set to default. Cherno makes a 'log' function that returns the message that it receives, and *for no reason*, puts it in the middle of the 'multiply' function he created. Without the optimization, we can see in the .asm file that the compiler calls for the 'log'function for no reason, which slows down the computer by adding additional line to the code. With the optimization turned on and compiling the file again, the whole line that calls for the redundant 'log' line is just gone, because the compiler decides to delete the whole section since it understands that it is unnecessary.
well done
Thanks, man
The .cherno thing he meant by it that the compiler will treat your file like any text file so you don't to name it by .cpp extension.
Infact you can compiler any text file that have cpp code in it
Abstract Syntax Tree and Java not java script
if abject file does not contain the call to message/ print message then how will our application print the message at the end of the day, that isn't optimization its data loss
Dude, this series is amazing, seriously! I come with a bit of background of assembly, c++, c# and python and you explain things so well!
Thank you very much for these videos :)
The background music is perfect. It keeps the viewer focused. Great job dude
Fuck men, I've been watching him for over a year now, and never noticed it, then came here to read comments, and now i can't unhear it anymore, can't focus on words coming from his mouth. Burn in hell!!!!!!!!!
@@geronimo9824 lol
@@geronimo9824 Um... hahaha
@@geronimo9824 It's probably because Rohit must be close enough to music instruments so that his sensitivity already gets more about sounds faster than you do. I'm a musician myself and one of the first stuff I noticed was the great tracks Cherno uses as bg sound.
Okay man seriously your C++ tutorials are the best programming tutorials in any language I've ever coded in. It feels so good, even if it's only scratching the surface, getting a good understanding of the underlying nuts and bolts of every line of code. Thank you very much!
Love the series. Please keep it up. There is a lot of unfinished cpp series on youtube. It would be a shame if this one will fall aswell.
Check out Derek Banas
Don't.
Let's support him on Patreon so that he'll continue doing this awesome work.
He said in a vlog so he will keep it up (if i dont missunderstand his words :D) but it can take up for years! to finish all 3 series.
Good to see that 3 years later the series is still going strong
Been programming c++ for just under a year now, consistently. It's amazing how I still learn new things everyday, especially from you. Thanks so much, man. I appreciate it so much.
Thank you for making the best C++ tutorial!
I found your channel and I am thrilled. I wish I could freeze time for anything but me, my computer, my internet connection and UA-cam servers in order to just get all this information in no time.
Super cool to see how the C++ code gets turned into Assembly and Machine Code, and also really helpful to have a better understanding of what the compiler is actually doing!
This is a very well done explication of the c++ compiler.
Reading the comments, I am so glad you are one of the first channels I found when I started looking for cpp tutorials...
Playing around like this is the absolute best way to learn the internals of programming. Not merely watching videos, but actually DOING the work. Now go play!!! 😁
I'm only a few videos in and it's such a breath of fresh air to find someone who knows their topic well enough to explain it in such easy terms. Preprocessing itself has been so badly explained to me by teachers at all levels and udemy 'instructors' and then here you go and show me that it's perhaps one of the simplest things you can imagine.
Thank you. Thank you for the effort you've made in creating this.
"so instead of fixing this like a normal person" cracked me up for some reason
7:18 this is useful for when you try to make your code as cursed as possible
Fast and with some background music, I think it's perfect to hold one's attention. I will recommend this series!
Great videos, thank you so much. I have been watching your videos. For brief notes, i asked gpt "How the C++ Compiler Works":
The C++ compiler transforms C++ source code into executable machine code through several stages. Understanding these stages can help you write more efficient and error-free code. Here’s an overview of how the C++ compiler works:
### 1. **Preprocessing**
- **Input:** Source code files (`.cpp`, `.h`).
- **Output:** Preprocessed source code.
- **Actions:**
- **Macro Expansion:** Expands all macros defined with `#define`.
- **File Inclusion:** Inserts the content of the included header files (`#include` directives).
- **Conditional Compilation:** Evaluates `#if`, `#ifdef`, `#ifndef`, and similar directives to include or exclude parts of the code.
- **Removing Comments:** Strips out comments from the source code.
### 2. **Compilation**
- **Input:** Preprocessed source code.
- **Output:** Assembly code.
- **Actions:**
- **Syntax Analysis (Parsing):** Checks the code for syntactical correctness. Converts the code into an Abstract Syntax Tree (AST).
- **Semantic Analysis:** Ensures the code adheres to the language rules and checks for semantic errors (e.g., type checking, variable declarations).
- **Intermediate Code Generation:** Converts the AST into an intermediate representation (IR).
- **Optimization:** Performs various optimizations on the IR to improve performance and reduce the code size.
- **Code Generation:** Translates the optimized IR into assembly code for the target architecture.
### 3. **Assembly**
- **Input:** Assembly code.
- **Output:** Object code (machine code).
- **Actions:**
- Converts the human-readable assembly code into machine code instructions specific to the target CPU architecture.
- Produces an object file (`.o` or `.obj`), which contains the machine code and additional information like symbol tables and relocation information.
### 4. **Linking**
- **Input:** Object code files and libraries.
- **Output:** Executable file.
- **Actions:**
- **Symbol Resolution:** Resolves references to functions and variables across different object files.
- **Relocation:** Adjusts addresses within the code and data sections.
- **Library Linking:** Includes necessary code from static libraries (`.lib` or `.a`) or dynamic/shared libraries (`.dll` or `.so`).
- Produces the final executable file that can be run on the target system.
### 5. **Loading (Execution Time)**
- **Input:** Executable file.
- **Output:** Running process.
- **Actions:**
- The operating system loads the executable into memory.
- Allocates memory for the program’s stack, heap, and data segments.
- Resolves dynamic library references (if any).
- Transfers control to the program’s entry point (usually the `main` function).
### Additional Details
- **Error Handling:** At each stage, the compiler checks for errors and warnings, providing feedback to the programmer.
- **Debugging Information:** The compiler can include debugging information in the object files to help with debugging.
- **Optimization Levels:** Compilers often offer various optimization levels (e.g., `-O1`, `-O2`, `-O3` in GCC) to control the trade-off between compilation time and the performance of the generated code.
### Example of a Compilation Process
For a file `main.cpp`, the typical compilation process using a command-line tool like `g++` might look like this:
```sh
g++ -o main main.cpp
```
This command tells the `g++` compiler to preprocess, compile, assemble, and link `main.cpp` into an executable named `main`.
By breaking down the compilation process into these stages, you can better understand how your C++ code is transformed into a running program and optimize or debug each part of the process effectively.
Usually when I work through video courses, I'll watch them at 1.5-2 x speed. When I see the total number of hours, I also factor the speed shift in and determine how much value a course has. Anywayz...none of that applies here :D I've worked through a number of C++ courses, but I can't resist starting from scratch with this series as I've already come across more than I had previously known. While most kids got a teddy-bear as their first gift, I'm sure you were given a laptop and a copy of Programming Principles and Practice Using C++ by Bjarne Stroustrup. No wonder EA are cranking out some amazing titles. I'm sure I'm not alone in saying that I really appreciate your effort and I'll be sure to contribute when I can. Cheers!
lmaooo 7:33 who would've thought that these things can be that much simple like i was amazed that you can just create any header file and write #include and it will just paste that thing lmao man, you are great at explaining things, i love you
After watching this video I started to LOVE C++, Visual Studio and The Cherno's Channel!!!
VS takes too much disk space.
Thanks for the great instruction. It is so much easier to understand by watching you going through the demonstration. I think at 11:43 it is the hexadecimal (0-F) representation. The assembly code is useful to debug some weird and tough bug. I also watched your video about the linking. It was very helpful too.
Wow, this series is fantastic. I'm making my way to patreon right now, because I don't want to this to stop.
Dude, I have gone through so many c++ series and almost all of them are either garbage or redundant. Your series is a pure gem. It will help me to grow my embedded systems skills. Cheers!
Quite simply the best learning resource I’ve found online for any topic. Thank you keep up the good work
I just started watching your series. I just want to say that I LOVE how you go into details about everything without making it boring.
C'mon! I believed that compiler does some magic. Feeling the same as when I realized that Santa is fake
Give me my ignorance back! : ))
00:00 - 10:02
The video discusses how the C++ compiler works, focusing on the compiling stage
The compiler's main task is to convert C++ code into an object file
It goes through pre-processing, tokenizing, and parsing stages to create an abstract syntax tree
The compiler then generates machine code for the CPU to execute
Each CPP file in a project results in a translation unit and object file
Preprocessor statements like include, define, and if are explained and demonstrated
The video provides a simple example of a multiply function and shows the pre-processed code
The process of including header files and using preprocessor statements is demonstrated in the video
09:56 - 17:45
The video discusses the preprocessor in C++ and demonstrates how to disable and enable certain code sections
It also explains how to compile C++ code into machine code and optimize it for speed
The video shows how constant folding works and how the compiler generates machine code for function calls
The importance of understanding the C++ compiler for debugging and advanced topics is emphasized
3:51 "Compile me like one of your .cpp files :3"
Dude. I'm taking a C++ class at WGU and I can't even begin to explain to you how helpful this series is. You're a boss.
Absolutely loving the series so far. Great job! Will you ever cover how to compile into DLL files and then use them as references in different projects?
DLLs are just like regular static libraries except you need the DLL next to the exe and you must export your functions to the DLL. Im sure Cherno will go in depth of this.
I didn't find any person like you to explain in the simplest possible way. I saw an everyday video about programming for 10 years but I never find a person to explain this detail. It's absolutely easy for me because I had experience in programming but if someone new to programming with your video learns readily.
BLIIIIIINK PLEASE BLINK
I've just started with operating system development at my university (TU Dortmund - Germany) and missed out this whole compilation part (preprocessing, compilation, assembling, linking). This video helped me out a lot. Thanks for that - you've earned yourself a new subscriber!
Edit: The quality of your education video is also top notch! Simple, in depth, no annoying background music, good examples. Keep it up!
"I've actually made another video specifically covering linking"
"Coming Soon..."
God dammit. I hate being early.
*laughs in 2020* >:D
imagine being early. Can't relate.
@@stevenflogio9892 *laughs in 2021* KEKW
lmao you were very early
@@stevenflogio9892 *laughs in 2021*
Bro that demonstration with the header file is really good. I never realized that #include was a literal copy and paste.
Once again, thank you for these videos, Cherno, but the music is very distracting. It might not be for you, but for a beginner trying to process all this new information while following the video, it certainly is.
I really do appreciate this, don't get me wrong.
This video has music? I just watched the whole thing and it went entirely unnoticed by me.
This is perfect. I am a software developer but do not have a formal cs degree, and this series has laid a solid foundation on stuff I had no clue how worked. Thanks
I did not wanted this to end for next 2 to 3 hrs ?? really !!
Visual comparison of before and after optimization powerfully illustrates what compilation does. I appreciate this level of detail and approach to explanation.
"C++ is text. That's it. It's just a text file."
me: *having existential crysis*
EDIT:
this was so pleasant to listen to like a cooking instruction. You really got it down man!
Wow, your explanation of header files was incredibly good and simple. As a beginner I kept seeing how header files were used, but not how they worked. Good job!
You could do more than one video a week, because at this rate I will have children before finishing the series... xd
pi He has a full time job and does this in his free time. He could skip the basic useless stuff though, but it's his series so he decides
Support him on Patreon.
This guy explain this shit much better than most of the professors on unis.
you should make compiler construction series as well. there isn't any good one out there.
Usman Shery can you recommend one??
Your understanding of c++ is very clean, and it has motivated me to watch more videos and continue where I left off trying to understand c++
Well in 11:28, the code is in its hexadecimal format not binary. Overall, good tutorial for C++ learners
i agree
The file is a binary file. It's just shown with hexadecimal characters by the text editor.
@@linocontreras8406 ^^^^^ thisssss
For Mac OS users using XCode:
- Getting the Preprocessor file : Editor > Assistant > Click on Counterparts > Select Preprocessor
- Getting the Assembly file : Editor > Assistant > Click on Counterparts > Select Assembly
"I hope you learned something new".
You bet.
haha
As C compiler optimizes and compiles code in to an executable. You too have compiled lot of information in to a short and precise video. You cleared lot of myths I had in my mind for this compiling process.
Thanks a lot.
I laughed my ass of when i seen that with the header files. Just copy pasta at it's finest.
This is fantastic. I have been programming for a couple months now and this cleared the water for so many things I was having trouble understanding. Thank you.
Is your last name...Bill?
no his last name is chernoproject
Yan Chernikov
Whoever doesn't like your videos, need to get a grip. You killin the game, The Cherno! Very articulate and concise explanations and code examples for anyone who isn't familiar with how it all works. I am 24 years in the game and I am hard to impress. You did that! Props!
11:26 this is hex decimal :D
Are you challenge me?
I've started watching your videos 3 years ago to learn C++ and just came back for basic knowledge and how C++ works in general under the hood and WOW, never expected to gain so much information again from these what I called "boring" videos.
I think I understood everything but the video was a bit too fast for my taste. I even thought I would have the video on 1.25x speed...^^
such a good series! Thanks.
Slight constructive feedback. Blink more.
You seem to have done jump cuts to make it flow better (which is great) but you also appear to not blink at all during the intro thanks to it. It's noticeable which makes it distracting (and sorta creepy).
So yeah, just try to blink normally even though its weird with lights/camera and stuff.
Yeah, people tend to notice if someone talking to them is blinking too often or not often enough. Since you have bright lights in your eyes in a situation like this you tend to blink too often so you have to consciously avoid doing that, aaaand then you might go the opposite direction.
It's not a big deal, but worth thinking of when recording videos.
Haha okay, I'll try. Thanks for the feedback. :)
Didn't even notice it at first, now I have to watch a staring zombie Cherno for 18 minutes, thanks xD
Interesting, but personally I don't care much about that. Though now it would be awkward if he started to blink more often now that I know that. See what you have done to my mind?
I didn't even notice. At the start of each jump cut it looks as if he just blinked anyway.
This is incredibly useful. Many thanks and hat's off to your teaching skills, very inspiring.
idk why people complaining for high quality free content. i get some people are really advanced, but I think even though I do speak c++ to put it that way, it's a nice refresher as well as it is a complete series from begin to end. if he does finish it.
I remember seeing this series few years ago and thinking that the channel deserves to be way more popular... And now in 2020: 335K subs, glad you've made it! :)
THE WAY YOU PROVE THINGS (LIKE HEADER FILES ARE CPIED THERE) IS AMAZING
By far the best video I have ever seen on this topic. Clear, concise, on-topic, with a lot of enlightening examples and with some very interesting background information. Congratulation!
10 years into fullstack web app, mobile and software programming, I wanted to learn C++ so I can create faster backends and create desktop app/games.
This is the only tutorial that explained perfectly how C++ works
Well you can get that the quality of the video is high from the astonishing rate of people truly satisfied in the comments below.. You are doing an amazing job here explaining also the background, it makes much more sense when things have a deeper reason. Thank you very much man!
I've been programming in C++ for 3432.76 years, and I learned something new here. Thanks!
Dude thank you for teaching, seriously. This exact subject was so uncovered and hand wavy at my University and you ripped into it perfectly.
Cherno, you are a brilliant teacher! Thank you so much. You explain things so clearly! Please keep up this great work.
I only started learning C++ today. Have been a web dev for 14 years, but want to dive into game programming. Your tuts are my go-to :)
Darn, I have to say, this tut is really impressive. I like your information density and how you present said information.
I just started the tut and I'm really looking forward to the rest of the videos in this playlist :D
Thanks and have a good one
Commenting for your exposure. The best channel on UA-cam for C++ !!!
Very in-depth tutorial and very pleasant background music
This is some high tier tutorial series. Please keep it up.
It must have took quite some effort for making such content for free. Evergreen content. Till C++ stays, this content remains relevant. Hats off Cherno! Thanks for these gem videos!
The amount of amazing information in this video just blew my mind. Thank You!
Your presentations are simply superb. I wish I worked with someone like you...
I think that your vids are the best on UA-cam by far for almost any programming language.
As a C++ programmer I like to review things watching videos like this. You are very clear explaining. Thanks for your videos!
Fantastically explained.
Been programming for a few years now, but never really jumped into CPP. Really good explanation of some of the things that go on when i hit that 'Build' button.
Wow i have been working with c++ and programming languages in general for a couple years now , but gotta say these tutorials are really good easy to understand , keep the good work Mate
This is such a great video! It helps a lot to understand what’s actually going on beneath the hood when I build projects
Thank you! this was very helpful!
I am happy to be here again Cherno, this time I will follow until the end. Just one note to add: 11:20 that's not binary, that's machine code; and object file can have an extension .obj (windows) or .o (linx) it depends on which compiler you use. I remember this video and seeing you doing those intermediate steps / outputs was amazing. Thank you very much. Best subscription in 10+ years
Oh my bad.. it is binary but with hexadecimal notation.. now I am confused I always thought that machine code and assembly were different things... i should remove this comment beforr someone quit 😄
Thank you for this series!!! You cover alot of stuff that has been a mystery to me....you explain C++ much more in depth than most people....you should charge for this content....your taking all the mystery out of C++ and making it look easy.
This is honestly the absolute best C++ video I have ever seen. Thanks you!
Dude I feel enlightened. Thank you! Just starting off with this and the way you tell all this excites me.... it's like discovering a new candy!!
Awesome video. It's simple to understand and it's actually very fun learning from you. Keep it up!
Wow, I am amazed by the content provided by this channel.
Really thank you very much TheChernoProject!
Seriously learning more from this free video series than my C++ class in school.
I came here thinking it'll be a beginner course, but you have a talent to mix beginner and advenced notions, i think your videos are perfect for anyone who tries to learn or perfect their Cpp skills, truly anyone can learn something here, that's a video quality i've not seen very often, best cpp course out here imo
(sry for my broken english, not native speaker and my last english class is getting a bit old ^^)
This video had been so valuable for me... Thank you very much. What you are doing in this channel is unique.
This has cleared so many doubts. Thanks a lot for this video.
this guy hasnt blinked at all in this video.
I've just started the series but thank you so very much. ❤️
I got 1,5 months to get sure on C++ (I've gone through the basics before, but your explanations are somehow catchy) and learn to work with Unreal engine.
You're saving me tons of time I don't have. 😄
Wait unreal engine uses c+++
@@lulsec
Sorry I don't really get what you mean, so I can't give a proper answer. 😔
@@jeanettefroderberg7271 nevermind Google gave me answer
You go pretty fast but you give great information. And you are a great teacher, I learn a lot of things not taught in basic classes but should be.