What does y -= m < 3 mean?

后端 未结 8 2055
面向向阳花
面向向阳花 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 21:00

    Most interesting is the amount of code it creates. On a simple Arduino system (compiler version 1.8.10) both the original and the

    y -= (m < 3 ? 1 : 0); 
    

    create the same code size. However, the 'if' version:

    if(m<3) {y -= 1;} 
    

    actually creates 8 bytes less code (4 instructions less). A good example of how creating clever code doesn't necessarily result in smaller code, especially with a good compiler.

提交回复
热议问题