是使用无效指针值用C是否合法? [英] Is using an invalid pointer value legal in C?
本文介绍了是使用无效指针值用C是否合法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下code是<一个href=\"http://stackoverflow.com/questions/1866461/why-should-i-not-try-to-use-this-value-after-delete-this/1866693#1866693\">undefined用C ++的行为(尽管它的工作好上几乎所有广泛使用的实现):
The following code is undefined behavior in C++ (although it will work okay on almost any widely used implementation):
int* pointer; //uninitialized - likely illegal pointer value
pointer++; //incrementing an illegal pointer is UB
是上面code合法使用C?
Is the above code legal in C?
推荐答案
这在C未定义的行为,以及因为在某些平台上,加载一个无效的指针到寄存器触发一个硬件故障。
It's undefined behavior in C as well because on certain architectures, loading an invalid pointer into a register triggers a hardware fault.
这篇关于是使用无效指针值用C是否合法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文