1 00:00:00,430 --> 00:00:07,990 Now let's embark on the compilation process, which begins with a set of source files that you intend 2 00:00:07,990 --> 00:00:09,040 to compile. 3 00:00:09,040 --> 00:00:14,680 So while it is possible to have just one source files, larger programs typically consist of multiple 4 00:00:14,680 --> 00:00:15,220 files. 5 00:00:15,220 --> 00:00:21,340 So this approach not only facilitates project management but also accelerates compilation. 6 00:00:21,340 --> 00:00:27,400 So if a single file undergoes changes, you only need to recompile that specific file instead of the 7 00:00:27,400 --> 00:00:28,780 entire code base. 8 00:00:28,780 --> 00:00:35,530 So this C source file contains macros indicated by hashtag define. 9 00:00:35,680 --> 00:00:43,420 Now we will create open the notepad here and we will create some define here. 10 00:00:43,420 --> 00:00:46,180 So this is the C file. 11 00:00:46,940 --> 00: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 12 00:00:56,060 --> 00:01:04,250 indicated that this is something that has macro and write it it on color font. 13 00:01:04,250 --> 00:01:07,670 So and we also have the include here. 14 00:01:07,670 --> 00:01:17,630 So the include directive here are used to incorporate header files with dot h extensions that the source 15 00:01:17,630 --> 00:01:18,590 files relies on. 16 00:01:18,590 --> 00:01:26,810 So during the preprocessing phase, these derivatives are expanded resulting in pure C that is ready 17 00:01:26,810 --> 00:01:28,040 for compilation. 18 00:01:28,040 --> 00:01:36,170 So to illustrate this process, let's examine an example application using the g c c compiler, which 19 00:01:36,170 --> 00:01:42,830 serves as a default compiler in many Linux distributions and including Ubuntu. 20 00:01:42,860 --> 00:01:45,650 The operating system installed on um. 21 00:01:45,650 --> 00:01:53,180 Uh, more that like the most popular operating system in Linux, but in Linux you will also get that 22 00:01:53,180 --> 00:01:54,920 GCC compiler here. 23 00:01:54,920 --> 00:02:01,910 So it's important to keep in mind that the results obtained from other compilers like Clang or Visual 24 00:02:01,910 --> 00:02:03,800 Studio will be similar. 25 00:02:03,800 --> 00:02:13,430 As I mentioned earlier, I'll code examples in this course will be compiled into 8664 code unless specified 26 00:02:13,430 --> 00:02:14,000 otherwise. 27 00:02:14,000 --> 00:02:16,490 So now we will. 28 00:02:17,430 --> 00:02:18,990 Chris Scott. 29 00:02:20,470 --> 00:02:29,800 And which firstly we will include the include the studio hatch because we will need that for print here. 30 00:02:29,800 --> 00:02:32,590 And after that we will define. 31 00:02:33,870 --> 00:02:34,770 Define. 32 00:02:35,740 --> 00:02:37,120 Format string. 33 00:02:37,690 --> 00:02:41,050 And this format string is going to be s, as you know. 34 00:02:41,620 --> 00:02:43,390 And we will also define. 35 00:02:44,510 --> 00:02:45,950 Define message. 36 00:02:47,000 --> 00:02:48,020 And it's going to be. 37 00:02:48,020 --> 00:02:48,830 Hello. 38 00:02:51,150 --> 00:02:52,650 Hello, world. 39 00:02:56,990 --> 00:03:00,710 And after that we will create integer Main here. 40 00:03:00,830 --> 00:03:05,090 And this integer XY here character. 41 00:03:06,740 --> 00:03:07,730 Is here. 42 00:03:09,110 --> 00:03:12,770 And after that we will print use the print function. 43 00:03:14,740 --> 00:03:15,290 Printf. 44 00:03:15,460 --> 00:03:16,180 Here. 45 00:03:16,210 --> 00:03:18,430 First we will pass the format string. 46 00:03:19,460 --> 00:03:25,040 And after that we will pass the message, which is Hello, world traditional message here. 47 00:03:25,040 --> 00:03:27,680 And after that we will return zero. 48 00:03:28,490 --> 00:03:31,430 Let's close the braces here. 49 00:03:34,090 --> 00:03:34,930 That's it. 50 00:03:35,470 --> 00:03:43,540 And in a moment here, you will see what happens with this file in the rest of the compilation process. 51 00:03:43,540 --> 00:03:47,260 But for now, we will just consider the output of the preprocessing stage. 52 00:03:47,260 --> 00:03:54,760 So by default, GCC will automatically execute all compilation phases, so you have to explicitly tell 53 00:03:54,760 --> 00:04:01,440 it to stop after preprocessing and to show you intermediate output. 54 00:04:01,450 --> 00:04:01,780 Right. 55 00:04:02,100 --> 00:04:05,830 We will tell the GCC that and. 56 00:04:07,050 --> 00:04:08,970 Here for GCSE. 57 00:04:09,000 --> 00:04:12,780 This can be done using the common GCSE. 58 00:04:13,200 --> 00:04:14,220 Let's clear here. 59 00:04:14,220 --> 00:04:19,680 So gcse uppercase e parameter and p parameter. 60 00:04:19,680 --> 00:04:31,710 So where e here tells GCSE to stop after pre-processing and P here causes the compiler to omit the debugging 61 00:04:31,710 --> 00:04:34,860 information so that the output is a bit cleaner. 62 00:04:34,860 --> 00:04:35,250 Right. 63 00:04:35,250 --> 00:04:38,310 So here we will write GCC. 64 00:04:39,850 --> 00:04:46,450 E p And after that we all sorry, we need to go to desktop because we saved this file in desktop. 65 00:04:46,450 --> 00:04:50,230 And here let's LZ Oops. 66 00:04:52,500 --> 00:04:55,020 Let's save it on desktop here. 67 00:04:59,630 --> 00:05:00,830 And here. 68 00:05:01,770 --> 00: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. 69 00:05:16,580 --> 00:05:18,040 My apps. 70 00:05:18,440 --> 00:05:20,050 And here it is. 71 00:05:20,060 --> 00:05:20,960 So. 72 00:05:23,190 --> 00:05:26,920 This is preprocessing phase here and we have this information. 73 00:05:26,940 --> 00:05:36,060 So the studio dot h heater is included, included in this entirety with all of its type definitions, 74 00:05:36,060 --> 00:05:42,620 global variables and functions, prototypes copied in to the source files. 75 00:05:42,630 --> 00:05:49,920 So because this happens for every include directory directory here directive and let's actually copy 76 00:05:49,920 --> 00:05:50,430 that. 77 00:05:55,510 --> 00:06:00,610 And we will copy that right now and we will paste and analyze it further. 78 00:06:04,220 --> 00:06:04,850 New. 79 00:06:04,850 --> 00:06:06,020 And that's it. 80 00:06:10,430 --> 00:06:12,800 And here we have integer Main here. 81 00:06:12,800 --> 00:06:13,610 So. 82 00:06:15,080 --> 00:06:23,330 And the preprocessor also really expands our use of any macros you define using, define. 83 00:06:23,330 --> 00:06:30,590 And in this example, this means both arguments here, the format string and here the format string 84 00:06:30,590 --> 00:06:38,810 and message are evaluated and replaced by the constant strings that they represent here. 85 00:06:38,960 --> 00:06:44,750 But strangely, we don't have the format string format, string. 86 00:06:44,750 --> 00:06:46,760 So we have this one. 87 00:06:49,610 --> 00:06:51,920 Mistyped this string here. 88 00:06:52,010 --> 00:07:01,700 And if you try to do that, like generally usually compile this my apk, we will get an error here because 89 00:07:01,700 --> 00:07:07,310 we have this string not defined properly because of the. 90 00:07:09,440 --> 00:07:10,100 Vermis. 91 00:07:12,050 --> 00:07:12,950 Yeah, that's it. 92 00:07:12,950 --> 00:07:16,280 And now if we compile this, this will compile without problem. 93 00:07:16,280 --> 00:07:18,550 And let's run this again. 94 00:07:18,560 --> 00:07:22,890 And here, as you can see, here we are seeing s and hello world here. 95 00:07:26,040 --> 00:07:26,910 Now, let's. 96 00:07:30,220 --> 00:07:32,020 And as you can see here. 97 00:07:33,250 --> 00:07:38,830 This means that both arguments to printf which is. 98 00:07:39,510 --> 00:07:48,910 Format, string and message are evaluated and replaced by the constant strings that they represent. 99 00:07:48,930 --> 00:07:56,820 So this was the preprocessing phase of C and compiled languages. 100 00:07:56,820 --> 00:08:00,090 And in next lecture we will also learn the compilation phase. 101 00:08:00,090 --> 00:08:02,130 So I'm awaiting you in the next lecture.