WEBVTT

00:00.430 --> 00:07.990
Now let's embark on the compilation process, which begins with a set of source files that you intend

00:07.990 --> 00:09.040
to compile.

00:09.040 --> 00:14.680
So while it is possible to have just one source files, larger programs typically consist of multiple

00:14.680 --> 00:15.220
files.

00:15.220 --> 00:21.340
So this approach not only facilitates project management but also accelerates compilation.

00:21.340 --> 00:27.400
So if a single file undergoes changes, you only need to recompile that specific file instead of the

00:27.400 --> 00:28.780
entire code base.

00:28.780 --> 00:35.530
So this C source file contains macros indicated by hashtag define.

00:35.680 --> 00:43.420
Now we will create open the notepad here and we will create some define here.

00:43.420 --> 00:46.180
So this is the C file.

00:46.940 --> 00:56.030
Macro here, so we will save it as a C main dot, my app dot C and here, as you can see here, Mousepad

00:56.060 --> 01:04.250
indicated that this is something that has macro and write it it on color font.

01:04.250 --> 01:07.670
So and we also have the include here.

01:07.670 --> 01:17.630
So the include directive here are used to incorporate header files with dot h extensions that the source

01:17.630 --> 01:18.590
files relies on.

01:18.590 --> 01:26.810
So during the preprocessing phase, these derivatives are expanded resulting in pure C that is ready

01:26.810 --> 01:28.040
for compilation.

01:28.040 --> 01:36.170
So to illustrate this process, let's examine an example application using the g c c compiler, which

01:36.170 --> 01:42.830
serves as a default compiler in many Linux distributions and including Ubuntu.

01:42.860 --> 01:45.650
The operating system installed on um.

01:45.650 --> 01:53.180
Uh, more that like the most popular operating system in Linux, but in Linux you will also get that

01:53.180 --> 01:54.920
GCC compiler here.

01:54.920 --> 02:01.910
So it's important to keep in mind that the results obtained from other compilers like Clang or Visual

02:01.910 --> 02:03.800
Studio will be similar.

02:03.800 --> 02:13.430
As I mentioned earlier, I'll code examples in this course will be compiled into 8664 code unless specified

02:13.430 --> 02:14.000
otherwise.

02:14.000 --> 02:16.490
So now we will.

02:17.430 --> 02:18.990
Chris Scott.

02:20.470 --> 02:29.800
And which firstly we will include the include the studio hatch because we will need that for print here.

02:29.800 --> 02:32.590
And after that we will define.

02:33.870 --> 02:34.770
Define.

02:35.740 --> 02:37.120
Format string.

02:37.690 --> 02:41.050
And this format string is going to be s, as you know.

02:41.620 --> 02:43.390
And we will also define.

02:44.510 --> 02:45.950
Define message.

02:47.000 --> 02:48.020
And it's going to be.

02:48.020 --> 02:48.830
Hello.

02:51.150 --> 02:52.650
Hello, world.

02:56.990 --> 03:00.710
And after that we will create integer Main here.

03:00.830 --> 03:03.740
And this integer XY here.

03:04.220 --> 03:07.730
Character Visualz here.

03:09.110 --> 03:12.770
And after that we will print use the print function.

03:14.740 --> 03:15.290
Printf.

03:15.460 --> 03:16.180
Here.

03:16.210 --> 03:18.430
First we will pass the format string.

03:19.460 --> 03:25.040
And after that we will pass the message, which is Hello, world traditional message here.

03:25.040 --> 03:27.680
And after that we will return zero.

03:28.490 --> 03:31.430
Let's close the braces here.

03:34.090 --> 03:34.930
That's it.

03:35.470 --> 03:43.540
And in a moment here, you will see what happens with this file in the rest of the compilation process.

03:43.540 --> 03:47.260
But for now, we will just consider the output of the preprocessing stage.

03:47.260 --> 03:54.760
So by default, GCC will automatically execute all compilation phases, so you have to explicitly tell

03:54.760 --> 04:01.440
it to stop after preprocessing and to show you intermediate output.

04:01.450 --> 04:01.770
Right.

04:02.100 --> 04:05.830
We will tell the GCC that and.

04:07.050 --> 04:08.970
Here for GCSE.

04:09.000 --> 04:12.780
This can be done using the common GCSE.

04:13.200 --> 04:14.220
Let's clear here.

04:14.220 --> 04:19.680
So gcse uppercase e parameter and p parameter.

04:19.680 --> 04:31.710
So where e here tells GCSE to stop after pre-processing and P here causes the compiler to omit the debugging

04:31.710 --> 04:34.860
information so that the output is a bit cleaner.

04:34.860 --> 04:35.250
Right.

04:35.250 --> 04:38.310
So here we will write GCC.

04:39.850 --> 04:46.450
E p And after that we all sorry, we need to go to desktop because we saved this file in desktop.

04:46.450 --> 04:50.230
And here let's LZ Oops.

04:52.500 --> 04:55.020
Let's save it on desktop here.

04:59.630 --> 05:00.830
And here.

05:01.770 --> 05:15.450
Here we have my apk and clear so gcc e p and after that we will pass our file which is named my APK.

05:16.580 --> 05:18.040
My apps.

05:18.440 --> 05:20.050
And here it is.

05:20.060 --> 05:20.960
So.

05:23.190 --> 05:26.920
This is preprocessing phase here and we have this information.

05:26.940 --> 05:36.060
So the studio dot h heater is included, included in this entirety with all of its type definitions,

05:36.060 --> 05:42.620
global variables and functions, prototypes copied in to the source files.

05:42.630 --> 05:49.920
So because this happens for every include directory directory here directive and let's actually copy

05:49.920 --> 05:50.430
that.

05:55.510 --> 06:00.610
And we will copy that right now and we will paste and analyze it further.

06:04.220 --> 06:04.850
New.

06:04.850 --> 06:06.020
And that's it.

06:10.430 --> 06:12.800
And here we have integer Main here.

06:12.800 --> 06:13.610
So.

06:15.080 --> 06:23.330
And the preprocessor also really expands our use of any macros you define using, define.

06:23.330 --> 06:30.590
And in this example, this means both arguments here, the format string and here the format string

06:30.590 --> 06:38.810
and message are evaluated and replaced by the constant strings that they represent here.

06:38.960 --> 06:44.750
But strangely, we don't have the format string format, string.

06:44.750 --> 06:46.760
So we have this one.

06:49.610 --> 06:51.920
Mistyped this string here.

06:52.010 --> 07:01.700
And if you try to do that, like generally usually compile this my apk, we will get an error here because

07:01.700 --> 07:07.310
we have this string not defined properly because of the.

07:09.440 --> 07:10.100
Vermis.

07:12.050 --> 07:12.950
Yeah, that's it.

07:12.950 --> 07:16.280
And now if we compile this, this will compile without problem.

07:16.280 --> 07:18.550
And let's run this again.

07:18.560 --> 07:22.890
And here, as you can see, here we are seeing s and hello world here.

07:26.040 --> 07:26.910
Now, let's.

07:30.220 --> 07:32.020
And as you can see here.

07:33.250 --> 07:38.830
This means that both arguments to printf which is.

07:39.510 --> 07:48.910
Format, string and message are evaluated and replaced by the constant strings that they represent.

07:48.930 --> 07:56.820
So this was the preprocessing phase of C and compiled languages.

07:56.820 --> 08:00.090
And in next lecture we will also learn the compilation phase.

08:00.090 --> 08:02.130
So I'm awaiting you in the next lecture.
