PROFESSOR: In this video, I'll explain to you a few things that actually happen when we press the Run It button at the bottom of your screen in Web Linux. At the end of this video, you'll understand all of the details of the build command that you see highlighted here as well as how to separately invoke those parts of the GCC command that are responsible for simply translating your C source code into machine language as well as the so-called link face that bundles necessary system libraries with your code to produce an executable program. To get us started, I have written this simple program with a main function that you see right here as well as one extra function right here. So let's quickly go through this code so we understand what it does. We'll run it, and then we'll separate it out into several files. The main function has an array in it called temperatures, and it contains seven numbers. And these are our temperatures. And let's say they're in degrees Celsius, so 6.9, 12.3, 9.0, 5.3, 9.8, 1.8, and 0.3. Furthermore, we have a variable of type double named average. And its job is to store the average of these seven temperatures. How do we get that average? We initialize this variable by calling the function average temp, which is the function declared down here. We'll get to that in a second. Next, we print that average seven day temperature with two decimal places. And the main function is done. Now, my function average temperature has a return type of a double because it returns the average temperature of these seven temperatures. And we pass into it the temperature array. How do you pass an array to a function? Remember, an array is, in memory, simply one number stored right next to the next. So we simply pass a pointer to the zeroth element of the array to the function. And the compiler and computer can then figure out automatically where all the other numbers are stored. In addition, we need the number of temperature stored in the array, because an array doesn't know its own size. Now, how do we compute the average temperature of these seven temperatures? Well, we simply add up all the temperatures and divide by the number. So to add up the temperatures, I have declared here a variable result, initialized it as zero, and we add onto that zero all the number stored in the array. So for that, use an integer i so I can have a for loop. And the for loop runs exactly number of temperatures times. And we simply add to our variable result the ith temperature stored in the array. Finally, we divide by the number of temperature stored in the array in this resulting line right here. And just to be safe, we cast the number of temperatures, which is an integer, to a double to ensure that we're doing a correct proper division here and not an integer division. It would have been safe not to do so because resolve is a variable of type double, but it can never hurt to be extra cautious. Finally, the wave function returns result. We also need a prototype for the function, which is the header of the function with a semicolon in the end. And at the very top, we're including this standard input output library because we're using the print function. So let's run this. We can simply save first, and then hit the Run button. And sure enough, here on the right, you can see the program was executed. And it says the average seven day temperature is 6.49. And that's in degrees Celsius. So I'm going to type ls here on the right. I now have a file named program.c. That's the file that saves my source code. And another file that shows up in green on my screen called program. That's the executable program. We can actually call that by simply typing ./program here on the right. And it also executes the program. It doesn't really compile it. It simply executes it. Now, in order to build this program, we executed this build command that you see at the bottom of your screen. We could have also built the program by typing this built command over in the terminal window on the right. I'm going to be a little bit lazy and simply type gcc, and I'm going to omit all these so-called flags. These flags that you see from -std=C11 all the way through =wextra, those are compiler flags. The first one, the -std=C11 tells the compiler which C standard to use. The C standard we're using here is C11. That's a modern C standard. The -Wall means to display all warnings. Sometimes the compiler registers a warning because it thinks you did something wrong, but it doesn't break the build command. So in theory, you could still built the executable, but it's safe to always look at these warnings and try to fix them because typically, there's an error in your program. So that's what that does. Then this -fmax-errors here, that tells the compiler well, after 10 errors, stop, stop compiling and throwing more errors because I'll get overwhelmed. And the -Wextra means extra warnings that are not included yet in the w all will also be displayed. I want to show you that I can also build the executable program by simply typing the command in the terminal window to make sure you believe me, I'm going to first delete the executable programs. R is the remove command. Now, when that type ls, it's gone. And when I try to execute program, that no longer works, and so now I'm going type GCC minus O program that specifies the name of the output file. Minus O stands for output file name so program is my executable. And program.C is the program I want to compile. And now, when I type ls, program exists again, and I can execute it. And it works just as well as before. What would happen if we didn't specify the output file name? Let's quickly understand why we have to do that. So again, let's remove the executable. And it's gone. And now, let's simply type GCCprogram.C. Let's see what happened. There was a file now called a.out. That is actually my executable program. So I can call that s./a.out, and there it is. It works just as well. But who wants their program to be called a.out? Now, let me show you what actually happens behind the scenes when you call GCC. The first thing that happens is the preprocessor is called, which means it's a simple textual replacement. For example, the contents of scdio.h is found, which is a text file, and it's actually verbatim copied into your source code. There are other things that the preprocessor does, but we're not going to go into those details. Next, the source code is translated into machine language into a so-called object file. That object file in and of itself cannot be executed. But it is the binary computer readable version of your code. And we can force that only that step happens by typing GCC. Again, we want to specify the output file name program.o, but now I want to stop at the object face program.c This is what we normally would have typed. We now, in addition to that, give the compiler an option -c. This flag, -c, tells the compiler I only want to translate into machine language. I do not yet want to create an executable program. So when I run this GCC command, and now I type ls, there is a program.o and along with my program.c. But I can't run that. You can see that because it didn't change color, but if I tried to run it, permission denied. It doesn't work, and if I try to look at it, it is a bunch of gibberish. It is the machine language version of my program. So let's quickly clear the screen so we don't have to look at that. So again, here's what we have. So how do we make that into something that I can run? I need to invoke the linker. That is also invoked by simply typing GCC. So GCC is sort of a name for all kinds of things that are happening all at the same time. But I can separate them out. And this is important for separate compilation. That's why I'm showing this. So GCC again. I want to specify the name of my output file. This time, I want to create my program. And what I want to stick into GCC is program.o because I already have this object file. And now, when I type ls, this executable program exists. And when I run that, it does my average seven day temperature. So the compiler really does a number of things. It calls the preprocessor, then it translates your code into a language the computer can actually read. And that is then taken by the linker, which creates the executable program. So now you know how to separately compile and link your code into an executable program. This is necessary in understanding how to split your source code up over multiple source files. That's what we'll talk about next.