我正在尝试优化一些代码,我想知道是否像
这样的条件的返回值(1>0)
在 c99 中总是 1 吗?我在网上找不到答案,我用 gcc 做的一些测试似乎表明这是真的。但这是语言规范的一部分吗?
具体代码(步进方 block 算法):
to_run->data[(y / 2) * (my_grid->width / 2) + (x / 2)] =
(up[0] > level) +
(up[1] > level) << 1 +
(down[0] > level) << 2 +
(down[1] > level) << 3;
最佳答案
是的。
C99 §6.5.8 Relational operators
Each of the operators
<
(less than),>
(greater than),<=
(less than or equal to), and>=
(greater than or equal to) shall yield1
if the specified relation is true and0
if it is false. The result has typeint
关于C99条件返回值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20119415/