[嵌入式linux] 请问这句代码什么意思?(复合语句)

[复制链接]
2447|2
 楼主| fineamy 发表于 2007-3-30 11:34 | 显示全部楼层 |阅读模式


incr = align >> PAGE_SHIFT ? : 1;

是否它等价于

incr = align >> PAGE_SHIFT ? (align >> PAGE_SHIFT) : 1;
 楼主| fineamy 发表于 2007-4-2 09:24 | 显示全部楼层

语句没问题,


The middle operand in a conditional expression may be omitted. Then if the first operand
is nonzero, its value is the value of the conditional expression.
Therefore, the expression
x ? : y
has the value of x if that is nonzero; otherwise, the value of y.
This example is perfectly equivalent to
x ? x : y
In this simple case, the ability to omit the middle operand is not especially useful. When it
becomes useful is when the first operand does, or may (if it is a macro argument), contain a side effect. Then repeating the operand in the middle would perform the side effect twice.
Omitting the middle operand uses the value already computed without the undesirable
effects of recomputing it.

This is GCC Extensions to the C Language Family
sinanjj 发表于 2011-8-14 14:18 | 显示全部楼层
看好lz.
您需要登录后才可以回帖 登录 | 注册

本版积分规则

14

主题

59

帖子

1

粉丝
快速回复 在线客服 返回列表 返回顶部