C + + Primer Plus 6th reading notes-Nineth chapter memory models and namespaces

Source: Internet
Author: User

1. Compiling separately

What is often included in the 1.1 header files:

    • Function prototypes
    • Symbolic constants defined with # define or const
    • Structure Declaration
    • class declaration
    • Template declaration
    • Inline declaration

1.2 You only need to add the source code files to the project without having to add the header files. This is because using the # include management header file.

1.3 Avoid including the same header file multiple times

1 #ifndef Coordin_h_ 2 #define Coordin_h_3// place include file contentshere4#endif

2. Storage continuity, scope, and connectivity

1. Storage solution:

    • Automatic storage persistence-variables declared in the function definition, 2 types
    • Static storage persistence-variables defined outside the function and variables defined using the keyword static, 3 kinds
    • Thread storage Persistence (C++11)-Thread_local declaration
    • Dynamic storage persistence-memory allocated with the new operator persists until it is disposed with the delete operator or the program ends

2. The names that are linked externally can be shared between files, and the internal name of the link is shared only by functions in one file.

3. Using the keyword register, it is recommended that the compiler use CPU registers to store automatic variables, which are designed to increase the speed of accessing variables. (Same as the previous usage of auto, c++11 obsolete).

4. Static storage persistence variables provide 3 features: external linkage (external declaration of code blocks), internal chaining (code block external static declaration), and no connectivity (code block internal static declaration). By default, static variables that are not explicitly initialized are set to 0 by the compiler.

5. c++11 New keyword constexpr to increase the way you create constant expressions.

6. The reference declaration uses the keyword extern and is not initialized. If you want to use an external variable in more than one file, you only need to include the definition of the variable in a file (a single definition rule), but in all other files that use the variable, you must declare it with the keyword extern.

7. The scope resolution operator (::) indicates that the global version of the variable is used.

C + + Primer Plus 6th reading notes-Nineth chapter memory models and namespaces

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.