当前位置:网站首页>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;
}
边栏推荐
- LinkedList源码分享
- "No title"
- excel高级绘图技巧100讲(二十二)-如何对不规则数据进行分列
- Pytorch框架学习记录12——完整的模型训练套路
- 漏洞分析丨HEVD-0x6.UninitializedStackVariable[win7x86]
- StringTable Detailed String Pool Performance Tuning String Concatenation
- 【luogu P1912】诗人小G(二分栈)(决策单调性优化DP)
- Common pits in the Go language
- LTE time domain and frequency domain resources
- Multithreaded producers and consumers
猜你喜欢
Hiking, cured my mental internal friction
Godaddy domain name resolution is slow and how to use DNSPod resolution to solve it
徒步,治好了我的精神内耗
AQS原理和介绍
外骨骼机器人(七):标准步态数据库
[Energy Conservation Institute] Comparative analysis of smart small busbar and column head cabinet solutions in data room
【Dart】dart之mixin探究
进行交互或动画时如何选择Visibility, Display, and Opacity
[Energy Conservation Institute] Application of Intelligent Control Device in High Voltage Switchgear
WeChat applet cloud development | personal blog applet
随机推荐
Buttons with good user experience should not have hover state on mobile phones
【微信小程序】【AR】threejs-miniprogram 安装(76/100)
使用百度EasyDL实现厂区工人抽烟行为识别
基于FPGA的任意字节数(单字节、多字节)的串口(UART)发送(含源码工程)
C专家编程 第1章 C:穿越时空的迷雾 1.3 标准I/O库和C预处理器
tiup mirror
Pytorch框架学习记录8——最大池化的使用
system collection
C专家编程 序
织梦发布文章提示body has not allow words错误
Use WeChat official account to send information to designated WeChat users
【Social Media Marketing】How to know if your WhatsApp is blocked?
面试突击70:什么是粘包和半包?怎么解决?
网络安全与基础设施安全局(CISA):两国将在网络安全方面扩大合作
Nacos 配置中心
JS提升:如何中断Promise的链式调用
Telnet弱口令渗透测试
如何让定时器在页面最小化的时候不执行?
Goroutine Leaks - The Forgotten Sender
Kubernetes 如何实现组件高可用