Object-Oriented Programming 1 winter operations Quiz

This work belongs courses 2020 Object-Oriented Programming (Fuzhou University - School of Mathematics and Computer Science)
Where the job requires Object-oriented programming winter operations 1
The target job 1. Install the C ++ development environment (see appendix)
2. Complete the quiz, practice questions and programming questions
3. Publish blog
Text of the job Object-Oriented Programming 1 winter operations Quiz
Other references Advantages and disadvantages of "turn" c brief language
C language advantages and disadvantages
c language compiler process detailed, pre-compiler, assembler, linker (full dry)
C language compilation process

1. If you do not know C ++, please answer the following questions: What do you think C language defects (Where do you think the use is not easily). If you already know C ++, please answer the following questions: Do you think C ++ and C language than what advantages.

A: Because I was in contact with school C language, C ++ and understand less (though recently started to see "C ++ Primer Plus"), so in this FAQ first small problem.

(1) missing from the file header contains the actual common function (preset function less)

First of all, when I answer the question of the appropriate programming has been an annoyance, like on sorting it. Although we already know how to play with regard to the code of the sort. However, each time using a sort we must fight the corresponding code, but no corresponding function included in the header file, let's go directly to the call. You might say that we can write a function to call when you can go. However, at this time we are still going to prepare the corresponding function in order to call, it will waste some time. In the past few days I learned, I learned C ++ STL library contains the sort function allows to directly call us, I think this can solve our problems can not be done in C language, which is more convenient.

(2) C language pointer, the pointer concerned is often difficult to detect programming errors

In this connection, I refer to the shortcomings of the "C Primer Plus" in. Indeed when I use C language to solve programming problems in the use of pointers terms, often you will find some small errors difficult to find, just as in the use of pointer memory address, sometimes you have an extra " 'cause as" the p-= & A; " mistake. There is a saying that good: you want to have freedom must remain vigilant.

(3) C language data security there is a big flaw

On this point, what I got in the reference number of Bowen and data conclusion (Ref has been marked in the submitted job) on the example: For the index bounds of the array, have not been checked, resulting in data when it is written to run overflow error may cause the computer system to run the bottom of the crash, the data is lost, resulting in serious consequences. This is encapsulated in the data makes its C language data security there is a big defect. After it does, the problem we have done in the programming, there is a data overflow, I remember it was a problem to solve the problem of password encryption and decryption, when we compare the letter is a lowercase letter, assuming variable plus 32 some variables can cause data overflow (there may be some problem with my expression) to display as "\ 273", etc., and that's why I think security issues C language data exists in Operation. At the same time, I use gets function takes a string and run the program, I use Xcode's Run box will pop up this to say "warning:. This program uses gets (), which is unsafe" After reviewing the information, I know unsafe because you gave him a buffer, but you did not tell it how big this buffer in the end, do not know how much content input in the end, may be beyond the contents of the input end of the buffer, causing your program collapse, use fgets will be better, because you can specify its buffer size. I think this is reflected in the use of the C language insecurity.

(4) Run-time type checking is unavailable

There is no provision in the C language run-time type checking, for example, I pass floating-point values, and receive parameters of type integer then the value will be changed, it will not give any type of error message.

(5) namespace features

C does not provide a namespace function, so you can not use the same variable name again within a range. If the namespace functionality is available, then you may be able to reuse the same variable name.

For (4), (5) is something I learn from others in order to understand the blog, has posted a link to a specific job.

These are my views for the C language shortcomings, there may be some mistakes, I hope you can criticism, but also want to learn C ++ further in-depth comparison of the advantages and disadvantages of both languages, and be applied in future studies.

2. Access to relevant information, the compilation process briefly C language / C ++ is.

Answer: C language compilation process (reference links has been marked in the job):

(1) Pre-expand the header file / macro substitution / uncomment / conditional compilation

For example: we used "#include <stdio, h.> " Angle brackets are pre-defined to the system to get the file path (i.e., the C compiler systems coexist is provided in header files in the specified subdirectory) . After the file is found, replace the statement with the contents of the file.
There are common "#define" can replace constant.

(2) compile, check the syntax to generate the assembler 

Pre-compiler work to be done is through lexical analysis and parsing, after confirming that all instructions are in line with the rules of grammar, which is translated into an equivalent intermediate code representation or assembly code. It can be said that this step in the compilation process, it is essential (personal opinion).

(3) compilation, assembly code conversion machine code

Actually refers to the compilation process to translate assembly language code into machine instructions of target process. For each C language source code translation system to be treated, it will eventually go through this process and the corresponding target file. Machine language code stored in the object file that is equivalent to the source of goals.

(4) links, link together to generate executable

Generated by the assembler object file can not be executed immediately, in which there may be many problems unresolved. For example, the function of a source file may be referenced in a symbolic (e.g., variable or function calls, etc.) defined in another source file; An application may call functions in a library file, and the like. All of these issues need to be resolved before being treated linking programs. The main program is to link the relevant object files connected to each other, it is also about to sign a document referenced in connecting with the symbol defined in another file.

Guess you like

Origin www.cnblogs.com/lvhang/p/12232503.html
Recommended