In this chapter we do not speak too much, I will only explain some basic concepts, these basic knowledge will be very helpful to the future study of the reader.
Actually, we're going to start with VC6.0.
0:VC 6.0?
I have reason to believe that the majority of readers of the first computer practice, the first HelloWorld program, are on the VC 6.0. Most of the domestic textbooks, teachers of courseware, also with its VC 6.0 as a standard. Many students will persist in using the IDE, which has been forgotten by Microsoft for a long time, from the distant 1998. I will borrow VC 6.0 to explain some basic concepts.
First of all, what is VC 6.0? The VC stands for Microsoft Visual C + + and is an object-oriented, visual integrated programming system for developing Windows environment programs based on the C + + language of Microsoft Corporation. This bold word point two, first,VC is an integrated development environment (Integrated development environment), the IDE is an integrated code editor, compiler, debugger, visualization tools the software of a series of programming tools, imagine this is a tool box, inside the tools have everything. Second, VC is not designed for the development of C language applications, or even for the development of C + + language applications, it is designed for the "C + + language-based development of Windows environment Program" design software.
VC is just a tool compatible with Anis C (C89), but unfortunately it is not suitable for developing a C-only application or for developing Windows programs. We can now say, "6.0" This version number is from the VC 6.0 contains the "MFC 6.0" (Mfc:microsoft Foundation classes), which Microsoft used in C + + designed to develop Windows programs, some libraries. Unfortunately this library is now almost abandoned by developers, there are many newer than it, better things, why waste life on MFC.
Now there are a lot of updates, the better IDE,VC 6.0 is completely obsolete.
If the computer is good enough, please change VS2017 (eat configuration), vs support ANSI C, and provide some extended functions, if the pursuit of "pure" C language, you can also choose to install the clang plug-in. Otherwise you can use CODEBLOCK+GCC (specific installation, configuration please self-search data learning). As for Linux users, goodbye to you that.
What's 1:ide? Code Editor? Compiler?
To understand why writing a program requires so much software, readers must go back to the distant 20th century and experience how the programmers of the past wrote the program. Next I will announce a good news and a bad news. The bad news is that by the time the blog was published, humans had not been able to successfully design a time machine. The good news is that we still have Linux. To demonstrate, I installed an Ubuntu virtual machine using VMware Workstation (Ubuntu is a "release" of Linux, the specifics are too complex, but you can think of this as Linux for the time being), and will show in console mode how to write using only the keyboard, Compile and debug a HelloWorld program (Ubuntu actually has a graphical interface, but we only use console mode to do the demo).
We will use three tools, these three tools are preinstalled in most Linux systems
1. VI Code Editor. Just like the Notepad program in Windows, the Linux system also provides us with a software to edit simple text, usually VI. We need to use this program to write code.
2.GCC compiler. This program processes the code we write, and compiles and links the code that was originally just text into an executable file. Only executable files can run.
3.GDB Debugger. Sometimes we want to be able to step through the program to see if certain variables meet expectations. At this point we use the debugger, the debugger can let us debug the program run, detect errors, detect the efficiency of the Code.
The first step is to log into the system.
The second step, we find a folder to put our files, when we log on to the Linux console, the working directory of the console is the root directory of the current user. Use the LS (list) directive to list the files and folders under the current user directory.
The third step is to use the CD command to enter the folder (without clipping the graph), this folder is randomly selected.
[Email protected]:~$ cd Templates
Fourth step, create a new C language source file helloworld.c with the Touch command. Then use VI to edit the new text. (The fact is that you can create a new text directly using the second command)
Fifth step, write the code and save it.
The sixth step, compile with GCC, note that two optional parameters are used here, '-G ' indicates that debug information should be generated, and immediately after-O HelloWorld indicates that the output file is named HelloWorld (note that there is no suffix name.) If you do not use '-o ', the output file name is the default a.out)
Seventh step, compile complete, no error message. Immediately following, we execute the compiled HelloWorld, console output "HelloWorld", the program is correct.
Eighth step, we want to be able to run the program in order to debug and view some information. We use GDB to debug HelloWorld
Nineth step, use the List command to view the source code. We set a breakpoint on the third line and use the Run command to execute the program to the first breakpoint. The next command is then executed on the line until the program ends.
Any reader who reads here should be aware of how difficult it is for programmers to write a program when there is no graphical interface in the past. They have to use a program to write code (code Editor), a program to compile the code (compiler), a program to debug the compiled program (debugger). If they want a chart to take a look at the process of running the program, the memory, CPU, they have to write an extra program, in the console with ASCII characters to print the chart. (Visual Tools). Fortunately, now that we have the IDE, in most cases we just need to use the IDE from beginning to end. Unfortunately, the IDE does not work in a particular environment, for example, VS will silently compile when we write the program to provide real-time code hints and error hints. However, when we write a huge amount of code (some commercial software can be far more than dozens of MB), when the code is changed directly in VS, the compilation of VS will consume great memory and CPU time. So, you need to write code first, then compile and debug. I suggest that readers not only be content with a handy IDE, but also better understand some of the other tools.
2. How the code becomes a program
The code is purely literal. If we open a txt and write a helloworld in, can it execute? Can't, because it's just a text, we always say, '. C ' is the source file, '. h ' is the header file. In practice, however, the suffix is irrelevant, and in Windows, the suffix is simply a description of the file's type to the program that is trying to open the file. But the fact is, you in VC 6.0 new '. C ', is actually a text file, it and '. txt ' no difference. (although I say so, ask the reader not to try to write the code directly in TXT or Microsoft Word, there is actually a problem with the encoding format). We can use a very simple sentence to answer the question of the title, the code into the compiler, came out into the program.
But what does the compiler do? It does two things, one is compile, but a link.
The compilation part is that the compiler compiles every '. C ' you write into a '. O ' (intermediate file) that translates the code that can be processed into assembly code. But in particular, if a function is not defined in a source file, but is used in the source file, the compiler will go to see if the header file of the source file contains the declaration of the function, if found, make a mark here. Later, the part of the link, the compiler tries to link each intermediate file with the other intermediate files that they depend on, and correctly overwrite the previous markup, so that the entire program, each variable, each function declaration and definition are complete, each call function is declared, or the compilation fails.
Once the program's link is complete, the compiler packs it into an executable file, and in Windows you get a PE file (portable executable) with a suffix called '. exe '. In Linux, the suffix name is meaningless and selectable, so you get an elf file (executable and linkable files). The operating system will know how to properly load the EXE into memory and execute the assembly code by line. So the program can be executed correctly.
This chapter is here, and I hope readers will read this article to have a more vivid understanding of some concepts
1. IDE
2. Compiler
3. Debugger
4. Compiling, linking
Countryside Literacy C language Chapter 1