【转载】C语言中的undefined behavior/unspecified behavior - 序
嗷嗷的话:
这都是一些细枝末节的东西,我想不做编译器的话,大部分都很难碰到。研究学习这些只是出于对C语言一种偏执狂。
写出来是为了找到和我一样的偏执狂。
在随后的的文章中,首先我写一写191种undefined behavior。不一定是对的,只是我自己的理解。参考的标准是C99.
undefined behavior简单来说就是,如果你的程序违反了C标准中某些准则,那么具体会发生什么,C标准没有定义,也就说得到任何奇怪的结果,都是有可能的。比如说整数溢出就是一个undefined behavior。
unspecified behavior简单来说就是,C标准提供了多种可选方案,具体选择哪一个并没有定义。比如说,函数计算他参数的顺序是一个unspecified behavior。以任何顺序计算都可以。i = i++ + i++;的值也是一个unspecified behavior。
本系列其他文章传送门:
C语言中的undefined behavior系列(1)-- linkage of identifier
一下摘于C99标准。关于behavior的定义
behavior -- external appearance or action
implementation-defined behavior -- unspecified behavior where each implementation documents how the choice is made
EXAMPLE An example of implementation-defined behavior is the propagation of the high-order bitwhen a signed integer is shifted right.
locale-specific behavior -- behavior that depends on local conventions of nationality, culture, and language that each implementation documents
EXAMPLE An example of locale-specific behavior is whether the islower function returns true for characters other than the 26 lowercase Latin letters
undefined behavior -- behavior, upon use of a nonportable or erroneous program construct or of erroneous data,for which this International Standard imposes no requirements
NOTE Possible undefined behavior ranges from ignoring the situation completely with unpredictableresults, to behaving during translation or program execution in a documented manner characteristic of the environment (with or without the issuance of a diagnostic message), to terminating a translation or execution (with the issuance of a diagnostic message).
EXAMPLE An example of undefined behavior is the behavior on integer overflow
unspecified behavior behavior where this International Standard provides two or more possibilities and imposes no further requirements on which is chosen in any instance
EXAMPLE An example of unspecified behavior is the order in which the arguments to a function are evaluated.
【转载】C语言中的undefined behavior/unspecified behavior - 序的更多相关文章
- C语言中的undefined behavior
参考: http://www.cnblogs.com/aoaoblogs/archive/2010/08/31/1813982.html
- 转载 C语言中volatile关键字的作用
一.前言 1.编译器优化介绍: 由于内存访问速度远不及CPU处理速度,为提高机器整体性能,在硬件上引入硬件高速缓存Cache,加速对内存的访问.另外在现代CPU中指令的执行并不一定严格按照顺序执行,没 ...
- C语言中do...while(0)的妙用(转载)
转载来自:C语言中do...while(0)的妙用,感谢分享. 在linux内核代码中,经常看到do...while(0)的宏,do...while(0)有很多作用,下面举出几个: 1.避免goto语 ...
- 【转载】C语言中的static 详细分析
原blog地址:http://blog.csdn.net/keyeagle/article/details/6708077/ google了近三页的关于C语言中static的内容,发现可用的信息很少, ...
- C语言中.h和.c文件解析(转载)
转载:http://www.cnblogs.com/laojie4321/archive/2012/03/30/2425015.html 简单的说其实要理解C文件与头文件(即.h)有什么不同之处, ...
- C语言中file文件指针概念及其操作 (转载)
文件 文件的基本概念 所谓"文件"是指一组相关数据的有序集合. 这个数据集有一个名称,叫做文件名.实际上在前面的各章中我们已经多次使用了文件,例如源程序文件.目标文件.可执行文件. ...
- C语言中,头文件和源文件的关系(转)
简单的说其实要理解C文件与头文件(即.h)有什么不同之处,首先需要弄明白编译器的工作过程,一般说来编译器会做以下几个过程: 1.预处理阶段 2.词法与语法分析阶段 3.编译阶段,首先编译成纯汇编语句, ...
- c语言中time相关函数
工作中遇到的函数: int seed = time(NULL); srand(seed); signal(SIGINT, stop); signal(SIGUSR1, sig_usr1); 搜time ...
- C语言中的static 详细分析
转自:http://blog.csdn.net/keyeagle/article/details/6708077/ google了近三页的关于C语言中static的内容,发现可用的信息很少,要么长篇大 ...
随机推荐
- mapreduce job提交流程源码级分析(一)(原创)
首先,在自己写的MR程序中通过org.apache.hadoop.mapreduce.Job来创建Job.配置好之后通过waitForCompletion方法来提交Job并打印MR执行过程的log.H ...
- thinkphp中where方法
今天来给大家讲下查询最常用但也是最复杂的where方法,where方法也属于模型类的连贯操作方法之一,主要用于查询和操作条件的设置.where方法的用法是ThinkPHP查询语言的精髓,也是Think ...
- xxxx is not translated in zh-rCN, zh-rTW
1.异常提示: "image_content" is not translated in zh-rCN, zh-rTW 2.错误原因: 根据报错提示,是说我没有对string文件做 ...
- SSH 内网端口转发实战
导读 大家都知道SSH是一种安全的传输协议,用在连接服务器上比较多.不过其实除了这个功能,它的隧道转发功能更是吸引人. 如果两个内网之间的linux服务器需要互相登录,或需要互相访问内网某个端口,担忧 ...
- UITableview reloadData Animation 动画效果
http://blog.kingiol.com/blog/2013/10/22/uitableview-reloaddata-with-animation/ 运用到UITableview进行重新加载数 ...
- poj1860 bellman—ford队列优化 Currency Exchange
Currency Exchange Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 22123 Accepted: 799 ...
- Linux EOF使用
# cat << EOF > fileB 用法 例: vi ceshi.sh cat<<eof>file1 aaaa bbbb cccc dddd eof 操作 ...
- django signal 浅析
默认的signals极其参数 (django 1.6.5) 模型的(django/db/models/signal.py): from django.dispatch import Signal cl ...
- LocalResizeIMG前端HTML5本地压缩图片上传,兼容移动设备IOS,android
LocalResizeIMG前端HTML5本地压缩图片上传,兼容移动设备IOS,android jincon 发表于 2015-02-26 18:31:01 发表在: php开发 localresiz ...
- 【云计算】Docker云平台—Docker基础
Docker云平台系列共三讲,此为第一讲:Docker基础 参考资料: Docker官方文档:https://docs.docker.com/ Docker从入门到实践:https://yeasy.g ...