博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【转载】C语言中的undefined behavior/unspecified behavior - 序
阅读量:4597 次
发布时间:2019-06-09

本文共 1957 字,大约阅读时间需要 6 分钟。

嗷嗷的话:

这都是一些细枝末节的东西,我想不做编译器的话,大部分都很难碰到。研究学习这些只是出于对C语言一种偏执狂。

     写出来是为了找到和我一样的偏执狂。

     在随后的的文章中,首先我写一写191种undefined behavior。不一定是对的,只是我自己的理解。参考的标准是C99.

undefined behavior简单来说就是,如果你的程序违反了C标准中某些准则,那么具体会发生什么,C标准没有定义,也就说得到任何奇怪的结果,都是有可能的。比如说整数溢出就是一个undefined behavior。

unspecified behavior简单来说就是,C标准提供了多种可选方案,具体选择哪一个并没有定义。比如说,函数计算他参数的顺序是一个unspecified behavior。以任何顺序计算都可以。i = i++ + i++;的值也是一个unspecified behavior。

 

本系列其他文章传送门:

一下摘于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.

转载于:https://www.cnblogs.com/jiayouwyhit/p/3147583.html

你可能感兴趣的文章
努力,时间,坚持,自律
查看>>
真三 bug PT的凤凰
查看>>
???动态SQL
查看>>
js错误处理与调试理论和办法
查看>>
Binding.StringFormat不起作用的原理和解决
查看>>
css hack兼容写法
查看>>
CSS两列布局 一边固定 一边自适应
查看>>
Hadoop2.6.0 动态增加节点
查看>>
图论的一些概念、定理
查看>>
WebView用法
查看>>
Lecture 3: Planning by Dynamic Programming
查看>>
用flash代替图片IMG,设置动态效果链接
查看>>
关于JS的随笔(二)
查看>>
select()函数以及FD_ZERO、FD_SET、FD_CLR、FD_ISSET(转)
查看>>
webbug3.0菜鸟笔记1
查看>>
数组相关函数
查看>>
Python 和其他编程语言数据类型的比较
查看>>
T2695 桶哥的问题——送桶 题解
查看>>
HTML5 表单
查看>>
Android群英传》读书笔记 (3) 第六章 Android绘图机制与处理技巧 + 第七章 Android动画机制与使用技巧...
查看>>