What does y -= m < 3 mean?

后端 未结 8 2050
面向向阳花
面向向阳花 2021-01-30 20:03

While looking through some example C code, I came across this:

y -= m < 3;

What does this do? It it some kind of condensed for loop or som

8条回答
  •  星月不相逢
    2021-01-30 20:55

    I agree that the code is equivalent to if(m<3) y=y-1;

    However it is unsafe code because while FALSE is always 0, TRUE has had a couple of definitions. Nowadays TRUE is equal to 1 in most programming systems, but in older systems it was equal to -1 (where all bits where set to on, not just the last one). So if this code is running on an older platform it could translate to if(m<3) y=y-(-1); or if(m<3) y=y+1; Cross system compatibility is a big reason to avoid 'clever' code like this.

提交回复
热议问题