1, avoid the header file repeat containsTEST.H This macro means that if a macro variable is defined Test_h_ it is no longer defined #ifndef test_h_#define test_h_//header file Contents #endifOrTest.h tells the precompiled compiler to include only
compiler compiles a program, it compiles only one source file and generates the corresponding intermediate file (for the VC, the. obj file), and then the connector unifies all intermediate files to form an executable file. The problem is that when
#ifndef #define #endif防止的是 "repeating compilation" instead of "repeating definition"Duplicate compilation can result in duplicate definitions, but duplicate definitions are not the only source of duplicate compilationIt takes two steps to turn from
Transferred from: http://www.cnblogs.com/rocketfan/archive/2009/10/02/1577361.html
1. compilation unit: A. cc or. cpp file is used as a compilation unit to generate. O.
2. Definition and declaration of common data types, Function Definition and
Original: http://www.cnblogs.com/GavinDai/archive/2011/10/24/2222735.htmlWe are in the program design, always use the definition of variables and the declaration of variables, but sometimes we are not very clear about the concept, know how it is
Inline can be placed in. cpp, but only this CPP file can use it at this time.To make a public object, you must put it in. H. If you do not want to put it in. H, you must copy one copy of each CPP file.In fact, even if it is put in. H, it is also a
variable declarations and variable definitions
Variable definitions: Used to allocate storage space for a variable, and to specify an initial value for a variable. In a program, a variable has and has only one definition.
Variable declaration: Used
The difference between a macro and a function with parameters? Macro substitution does not take up a run time, only the compile time, and the function call takes up the elapsed time (allocation Unit, reservation field, value Pass, return), so each
First, preface
In C-language code or C + + code, macro definition #ifndef ... #define ... #endif主要是为了避免头文件重复引用, how is it a avoidance mechanism? This is related to the scope of the macro definition.
Two, macro definition scope
First, the scope of
There are many places in the C language where macro definitions are used, such as in header files to prevent header files from being repeatedly included:
#ifndef ctest_header_h
#define CTEST_HEADER_H
/header file content
#endif
Many macro
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.