Which is faster : if (bool) or if(int)?

后端 未结 8 2097
离开以前
离开以前 2020-12-07 14:48

Which value is better to use? Boolean true or Integer 1?

The above topic made me do some experiments with bool and in

8条回答
  •  無奈伤痛
    2020-12-07 15:15

    With GCC 4.5 on Linux and Windows at least, sizeof(bool) == 1. On x86 and x86_64, you can't pass in less than an general purpose register's worth to a function (whether via the stack or a register depending on the calling convention etc...).

    So the code for bool, when un-optimized, actually goes to some length to extract that bool value from the argument stack (using another stack slot to save that byte). It's more complicated than just pulling a native register-sized variable.

提交回复
热议问题