链接器解析多重定义的全局变量
16lz
2021-12-04
//first.c#include <stdio.h>void f(void);int x = 15213;int y = 15212;int main(){f();printf("x = ox%x y = 0x%x\n", x, y);return 0;}
//bar.cdouble x;void f(){x = -0.0;}
xxx@ubuntu-64bit-compile:~/share2/learning/csapp/project$ cc first.c bar4.c
xxx@ubuntu-64bit-compile:~/share2/learning/csapp/project$ ./a.out
x = ox0 y = 0x80000000
因为double 类型是8个字节, 而int 类型是4个字节。因此, 负值的双精度浮点表示覆盖存储中 x 和 y的位置。因此就会产生那样的打印结果。
为此, 在项目中, 得到了一条经验教训: 不要忽视 编译警告。。。。
这一点开发人员一直不注意。
更多相关文章
- android Uri获取真实路径转换成File的方法
- android sqlite 图片保存和读出
- Android(安卓)识别SIM卡类型
- 监听TextView的变动
- android 判断联网类型
- Android电池信息(Battery information)
- 安卓4.X系统 增加蓝牙接收文件类型
- JS判断终端类型的几种方法
- Android(安卓)DEX安全攻防战