- 论坛徽章:
- 2
|
回复 #64 pmerofc 的帖子
我也不是经常去翻标准的…… 做编译器的人才是标准专家
只是有时候希望代码的行为能够有某种保证时, 才去翻翻看有没有这种保证。
比如最近翻到3个比较受用的保证:
1. struct 中可以有padding, 但绝对不会出现在第1个field之前。
2. union中所有field的offset都是0 。
3. ==, !=, < ... 这些操作符的结果都是0或者1 。
我英文也很烂…… 6级都没过……
那段话是出自这里吧?
c99 6.5 Expressions p67
2 Between the previous and next sequence point an object shall have its stored value
modified at most once by the evaluation of an expression. Furthermore, the prior value
shall be read only to determine the value to be stored.70)
...
70) This paragraph renders undefined statement expressions such as
i = ++i + 1;
a[i++] = i;
while allowing
i = i + 1;
a[i ] = i;
没看懂……
我还搜了一些其他资料, 比如这个: http://www.embedded.com/story/OEG20020625S0041
依然没看懂…… 觉得有些歧义。 也许是我理解错了……
但是在附录中翻到一个对应的条款, 好像更容易理解一些:
c99 J.2 Undefined behavior p491
— Between two sequence points, an object is modified more than once, or is modified
and the prior value is read other than to determine the value to be stored (6.5).
那个prior真的很关键…… 指的是:
1. modify之前
2. sequence point之前
如果是2, 那基本就说得通了。 如果是1…… 还是不懂……
然后就困了睡了……
出门寻求场外援助去了
晚上回来看能不能将这这个词理解准确一些……
ident是什么? |
|