Talking about the two issues and statements in C ++, two problems defined

xiaoxiao2021-03-05  49

l

In C , variables, objects, functions require declarations, and need to be defined before use. This article is often ignored by beginners, but a very important issue, and provides good programming styles in this regard.

Since everyone is very familiar with the definition and use of local variables, this major summary I think two points should be paid attention to: 1. Relationship between header files and statements 2. Symbol constants and inline functions

l explains

First, the header file provides a set of concentrated positions for the forwarded Extern object declaration function declaration and the Inline function definition.

The header file provides two security assurance: First, ensure that all files contain the same statement of the same global object or function; second, if you need to modify the declaration, just change a header file to not only modify A declaration in a special file. If the application has a large header file, use the pre-compiled head file instead of the ordinary header file to greatly reduce the compilation time of the application.

Second, the header file should not contain a definition of non-inline functions or objects. Because if these definitions are included in two or more files of the same program, a repetition-defined compilation error is generated.

However, constants and inline functions can violate this rule because constants and inline functions can be defined multiple times, while the root is due to the reason for the compiler to expand constants and inline functions during compilation.

转载请注明原文地址:https://www.9cbs.com/read-34603.html

New Post(0)