wordpress 修改为中文字体怎么样关键词优化
因为有些情况重复包含头文件会出现重复定义或者导致多次包含导致增加编译时间。
下述是没有假如条件编译和宏定义的例子:
// common_functions.h
int addTwoNumbers(int a, int b);
// data_structures.h
#include "common_functions.h"struct MyStruct {int data;
};
// main_logic.h
#include "common_functions.h"
#include "data_structures.h"void processData();
#include "main_logic.h"int main() {int result = addTwoNumbers(3, 4);return 0;
}
上述代码从main.c开始,要包含addTwoNumbers的声明,因此要包含common_function.h的头文件,但是为了保证后续开发,一般main可能会包含多个函数声明,因此在这里先包含了main_logic.h头文件,然后main_logic.h又包含了两个头文件,其中common_function.h是我们需要的,到这里其实就完成了。
但是data_structures.h还能继续,展开发现里面还包含了common_function.h,这就是反复包含,如果在头文件中进行了定义,则会出现重复定义的错误,如果是这种情况,则会导致增加编译时长。
下述是包含了条件编译和宏定义的例子:
// common_functions.h
#ifndef COMMON_FUNCTIONS_H
#define COMMON_FUNCTIONS_Hint addTwoNumbers(int a, int b);#endif
// data_structures.h
#ifndef DATA_STRUCTURES_H
#define DATA_STRUCTURES_H#include "common_functions.h"struct MyStruct {int data;
};#endif
// main_logic.h
#ifndef MAIN_LOGIC_H
#define MAIN_LOGIC_H#include "common_functions.h"
#include "data_structures.h"void processData();#endif
内容和上述例子差不多,只是多加了条件编译和宏定义,在没有定义的时候进行定义。
我们按照上述的流程,在main_logic.h包含了两个头文件,其中common_function.h是我们需要的,我们进入common_function.h的时候发现没有定义COMMON_FUNCTIONS_H,于是进行了定义。
之后从data_structures.h进入common_function.h的时候,我们已经定义过COMMON_FUNCTIONS_H了,则不会再进入头文件进行处理。