注意include .h 文件的使用
来源:互联网 发布:天金加银软件下载 编辑:程序博客网 时间:2024/05/01 05:14
场景
(看到项目中有如下使用方式,觉得会存在弊端,占用不必要的内存,虽然结果没有问题。)
多个变量定义在一个fid.h文件,
多个cpp文件(比如100个)同时#include "fid.h"
弊端
任意一变量会在cpp文件中展开,如果fid.h被include了100次,任一fid.h中的变量将在可执行文件中定义100次,
之所以链接不会出错重复定义,是因为变量被const修饰后,变为内链接。
</pre>fid.h<pre name="code" class="cpp">#ifndef _FID_H_#define _FID_H_//---------------------- Account -----------------------------const int FID_ACCOUNT_BASE = 10000;const int FID_ACCOUNT_ID = FID_ACCOUNT_BASE + 0; const int FID_ACCOUNT_NAME = FID_ACCOUNT_BASE + 1; const int FID_ACCOUNT_PASSWORD = FID_ACCOUNT_BASE + 2; const int FID_ACCOUNT_COMPANY_ID = FID_ACCOUNT_BASE + 3; const int FID_ACCOUNT_TOKEN = FID_ACCOUNT_BASE + 4; const int FID_ACCOUNT_DEPARTMENT = FID_ACCOUNT_BASE + 5; const int FID_ACCOUNT_COMPANY_NAME = FID_ACCOUNT_BASE + 6; const int FID_ACCOUNT_ROLE = FID_ACCOUNT_BASE + 7; const int FID_ACCOUNT_PERMISSION = FID_ACCOUNT_BASE + 8; const int FID_ACCOUNT_CODE = FID_ACCOUNT_BASE + 9; const int FID_ACCOUNT_TELEPHONE = FID_ACCOUNT_BASE + 10; const int FID_ACCOUNT_PHONE = FID_ACCOUNT_BASE + 11; const int FID_ACCOUNT_EMAIL = FID_ACCOUNT_BASE + 12; const int FID_ACCOUNT_RM = FID_ACCOUNT_BASE + 13; const int FID_ACCOUNT_MSN = FID_ACCOUNT_BASE + 14; const int FID_ACCOUNT_QQ = FID_ACCOUNT_BASE + 15; const int FID_ACCOUNT_ADDRESS = FID_ACCOUNT_BASE + 16; const int FID_ACCOUNT_PASSWORD_ORG = FID_ACCOUNT_BASE + 17;
........#endif // _FID_H_
0 0
- 注意include .h 文件的使用
- 关于#include<bits/stdc++.h>头文件的使用
- #include<bits/stdc++.h>这个头文件的使用
- #include <afx.h>头文件的作用
- #include<unistd.h>头文件的理解
- math.h的使用注意
- include .h文件
- Android 使用include需要注意的坑
- 使用#include <pthread.h>
- 使用#include<bits/stdc++.h>包含C++的所有头文件
- easy UI使用include<>包含页面时以及加载js文件所注意的事项。
- php中使用include(require)嵌套包含文件时的一些注意问题
- 程序员自定义的一个头文件,怎样通过#include<xxx.h>调用而不是#include"xxx.h"
- 调用.h文件需要注意的地方
- 使用malloc函数时,#include<malloc.h>与#include<stdlib.h>的区别
- #include <unistd.h> 头文件
- c语言的头文件#include <limits.h>
- c语言的头文件#include <limits.h>
- PHP sprintf函数
- C的数组
- Enocean Serial Protocol 3 常用测试命令
- Android Toast连续点击只弹一次
- <二叉树 前中后 层序 非递归遍历 c语言实现>
- 注意include .h 文件的使用
- 高性能netty
- android 自动输入完成提示 自定义适配器适用于自定义分隔符带中文的提示
- 实训成果
- ios UIAlertView
- Haskell安装mysql(mac环境)
- CXF 实现webservice
- 亲身试验熟桐油涂装家具,最后更新,出结论
- 字典树(前缀树)的应用