ERROR: do not initialise statics to false
2024-08-27 04:19:19
Question about git commit rule
I git commit a patch,
The patch has a "static int xxxxxxxxxxxxxxxxxxxxxxxxxx = 0;"
It show error messge "ERROR: do not initialise statics to false"
Why can't initialize a static variable = false in function ?
All static variable that is uninitialize are moved to BSS section.
Linux initialize these static variable to zero in BSS section.
So just write "static variable" in function.
Example :
incorrect.c
#include <stdio.h>
int main()
{
static int xxxxxxxxxxxxxxxxxxxxxxxxxx = 0;
static int aaaaaaaaaaaaaaaaaaaaaaaaaa = 0;
printf("exit \n");
}
correct.c
#include <stdio.h>
int main()
{
static int xxxxxxxxxxxxxxxxxxxxxxxxxx;
static int aaaaaaaaaaaaaaaaaaaaaaaaaa;
printf("exit \n");
}
gcc -o correct correct.c
objdump -x correct | grep bss
24 .bss 00000010 0000000000601040 0000000000601040 00001040 2**2
0000000000601040 l d .bss 0000000000000000 .bss
0000000000601040 l O .bss 0000000000000001 completed.7262
0000000000601044 l O .bss 0000000000000004 aaaaaaaaaaaaaaaaaaaaaaaaaa.2200
0000000000601048 l O .bss 0000000000000004 xxxxxxxxxxxxxxxxxxxxxxxxxx.2199
0000000000601050 g .bss 0000000000000000 _end
0000000000601040 g .bss 0000000000000000 __bss_start
Reference:
http://www.jollen.org/blog/2007/01/no-zero-initialized-in-bss.htmlbvg
最新文章
- RMAN-06023: no backup or copy of datafile 1 found to restore
- Linux 下配置php开发环境
- IOS9 Swift
- [20140711] SQL Server page还原
- C++ 构造函数放置默认转换explicit关键字(2)
- SQL Developer不能删除和复制及部分键失效问题
- Windows下配置使用WinPcap
- bzoj1412: [ZJOI2009]狼和羊的故事
- Notepad++强大的代码补全和代码提示功能的方法
- TreeList
- Android中Drawable分类汇总(上)
- Spring4 AOP详解
- TypeError:Error #1009
- 谈谈使用Redis缓存时批量删除的几种实现
- C#语法——消息,MVVM的核心技术。
- Ubuntu 自动选择最快的镜像源
- 微信小程序多层嵌套循环,二级数组遍历
- 如何在VMware中安装Linux系统
- delphi c#语法转换
- css选择器,样式表导入
热门文章
- 第33天:封装自己的class类
- RT-thread 设备驱动组件之PIN设备
- 未找到与约束ContractName Microsoft.VisualStudio.Text.ITextDocumentFactoryService...匹配的导出
- 具体数学数论章-----致敬Kunth
- [洛谷P5107]能量采集
- [洛谷P4070][SDOI2016]生成魔咒
- BZOJ2553 [BeiJing2011]禁忌 【AC自动机 + dp + 矩乘优化】
- bzoj1867: [Noi1999]钉子和小球(DP)
- [CQOI2011]放棋子
- Linux下 ps -ef 和 ps aux 的区别及格式详解