当前位置:网站首页>C陷阱与缺陷 第7章 可移植性缺陷 7.6 内存位置0
C陷阱与缺陷 第7章 可移植性缺陷 7.6 内存位置0
2022-08-01 21:00:00 【weixin_客子光阴】
内存位置0
null指针并不指向任何对象。因此,除非是用于赋值或比较运算,处于其他任何目的使用null指针都是非法的。
严格来说,这并非一个可移植性问题:在所有的C程序中,误用null指针的效果都是未定义的。检查出这类问题的最简单办法就是,把程序移到不允许访问内存位置0的机器上运行。
揭示C语言是如何处理内存地址0的:
#include <stdio.h>
int main() {
char *p;
p = NULL;
printf("Location 0 contains %d\n", *p);
return 0;
}
边栏推荐
- Excel advanced drawing techniques, 100 (22) - how to respectively the irregular data
- 相亲模型与有限状态机
- Pytorch框架学习记录8——最大池化的使用
- 宝塔搭建PESCMS-Ticket开源客服工单系统源码实测
- iptables的使用简单测试
- 职场如象棋,测试/开发程序员如何突破成长瓶颈期?
- Common pits in the Go language
- Buttons with good user experience should not have hover state on mobile phones
- 算法---解码方法(Kotlin)
- 函数(二)
猜你喜欢
数据库单字段存储多个标签(位移操作)
Convolutional Neural Network (CNN) mnist Digit Recognition - Tensorflow
网络安全与基础设施安全局(CISA):两国将在网络安全方面扩大合作
New graduate students, great experience in reading English literature, worthy of your collection
JS提升:如何中断Promise的链式调用
R语言 线性回归的有关方法
Questions I don't know in database kernel interview(1)
基于FPGA的任意字节数(单字节、多字节)的串口(UART)发送(含源码工程)
Application of Acrel-5010 online monitoring system for key energy consumption unit energy consumption in Hunan Sanli Group
Nacos 配置中心
随机推荐
技术栈概览
[Personal work] Wireless network image transmission module
徒步,治好了我的精神内耗
Which websites are commonly used for patent searches?
STAHL touch screen repair all-in-one display screen ET-316-TX-TFT common faults
[Energy Conservation Institute] Application of Intelligent Control Device in High Voltage Switchgear
4.1 配置Mysql与注册登录模块
字符串
JS提升:如何中断Promise的链式调用
数据库内核面试中我不会的问题(1)
技能大赛训练:A部分加固题目
漏洞分析丨HEVD-0x6.UninitializedStackVariable[win7x86]
Remove 360's detection and modification of the default browser
tiup mirror genkey
R语言 pca主成分分析的主要方法
"Torch" tensor multiplication: matmul, einsum
网红驼背矫正产品真的管用吗?如何预防驼背?医生说要这样做
列表页常见的 hook 封装
和我一起写一个音乐播放器,听一首最伟大的作品
案例:MySQL主从复制与读写分离