C++基础(七) inline函数
inline 函数
将函数声明为inline可以避免函数调用的开销,空间换时间
调用函数步骤:
- 返回地址压栈
- 函数参数压栈
- 计算返回值
- 函数部分所有元素出栈,返回值
普通函数与inline函数的汇编代码对比
将函数声明为inline可以避免函数调用的开销,空间换时间
调用函数步骤:
普通函数与inline函数的汇编代码对比
const对象一经创建后其值不能再改变,所以const对象必须初始化
1 | const int i = 1; |
默认情况下,const对象仅在文件内有效。若需在不同文件使用同一const对象,则const变量不管是声明还是定义都添加extern关键字,这样只需定义一次就可以了
1 | extern const int bufSize; |
Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub.
类型 | 含义 | 最小尺寸 |
---|---|---|
bool | 布尔 | 未定义 |
char | 字符 | 8位 |
short | 短整型 | 16位 |
int | 整型 | 16位 |
long | 长整型 | 32位 |
long long | 长整型 | 64位 |
float | 单精度浮点数 | 6位有效数字 |
double | 双精度浮点数 | 10位有效数字 |
long double | 扩展精度浮点数 | 10位有效数字 |
static局部变量在当前文件等同于全局变量
static局部变量只能在当前文件访问,其他文件不能通过extern访问
static对象的构造在main函数前执行,析构在main函数结束后