C++ Primer Plus Reading Notes (1)

Introduction to C++

1. Three programming methods of C++:

  • Procedural language represented by C language (i.e. procedural programming)
  • Object-oriented language represented by classes
  • Generic programming supported by templates

2. The birth of C language

In the 1970s, in order to develop the UNIX operating system (which manages computer resources and enables interaction between users and computers), Bell Labs needed to develop a language that was simple, fast, and capable of effectively controlling hardware. Traditional assembly language requires direct manipulation of hardware (such as direct access to CPU registers and memory units) and is a low-level language. Because it targets different computer processors, different assembly languages ​​are required when porting the code to another computer. Write it (like when you buy a new car and the designer redesigns the location and functions and has to learn it all over again). However, UNIX is designed to work on different computers, which means that it is a high-level language that can be used on different platforms by translating the high-level language into a high-level language program through a special program called a compiler. Ritechie hopes to integrate the efficiency and hardware access capabilities of low-level languages ​​with the versatility and portability of high-level languages, and developed the C language.

3. Program Data Algorithm

C language was initially process-oriented, emphasizing algorithms. When the program scale expanded, it encountered organizational obstacles. In order to solve this problem, computer scientists proposed the structured programming method. The C language now also has the feature of using this method, branching (deciding what to do next) Structured (for, while, if else statements).

Top-down programming idea, large programs are decomposed into small programs. Organizing the study room will be broken down into sub-tasks such as organizing the desk, organizing the floor, and organizing the bookshelf.

Structured programming still encounters difficulties when facing large programs, developmentOOP (Object Oriented Programming, object-oriented), The idea is to design a data format that corresponds to the essential characteristics of the problem. In C++, a class is a specification that describes this new data format, and an object is a specific data structure constructed according to this specification. Classes are frameworks, and objects are instances, such as a class - person (name, title, salary, expertise, etc.), an object - (Li Wen, product manager, 20,000, product concept design, etc.).

Design a program that uses class objects. The process of moving from low-level organization (such as class) to high-level organization (such as program) is calledbottom-upProgramming. (Sometimes not necessarily bottom-up)

The new concepts of OPP: inheritance, polymorphism, virtual functions, overloading, and information protection. (object-oriented emphasis)

Generic programming: Usually writing a sort must be rewritten for specific data types (such as int and float), but generic programming does not consider the data type, but a Generics.

OPP is a tool for managing large projects, and generic programming provides tools for performing common tasks (sorting data, merging linked lists)

C++ duality: Covers OPP high-level abstractions, C provides low-level hardware access
Portability and standards: Just design a new compiler for the new platform, realizing code transplantation and the same set of standards.
Face two obstacles: different hardware and differences in programming languages.

C++ standard(omitted)

4. The process of creating a C++ program and running it:

  1. Code flow
    Source code-> Compiler-> Object code (.o)-> Linker (including startup code, library code)-> Executable code(.out)
  2. Compile
    Compiler extension: .C .cxx .cpp .c++ (generally use .cpp but UNIX does not support it)
    Compilation process:
    1. C++ is compiled into C and then compiled into an executable file
    2. C++ is compiled directly into an executable file
    3. When compiling multiple files (g++ main.cpp walk.cpp), (main.o, walk.o) will not be deleted. When a certain file (main.cpp) is changed, just recompile main.cpp and complete Link(g++ main.cpp walk.o)
5.GCC/G++

gcc and g++ are GNU's c & c++ compilers respectively. gcc/g++ generally has the following four steps when performing compilation:

  1. Preprocessing, generating .i files [preprocessor cpp].
  2. Convert the preprocessed file into assembly language and generate the file .s [compiler egcs].
  3. The .o file is generated from assembly to object code (machine code) [assembler as].
  4. Connect the target code and generate an executable program [linker ld].

Guess you like

Origin blog.csdn.net/kindel/article/details/118642133