Will bit-shift by zero bits work correctly?

后端 未结 6 919
轮回少年
轮回少年 2021-02-04 03:15

Say I have a function like this:

inline int shift( int what, int bitCount )
{
    return what >> bitCount;
}

It will be called from diffe

6条回答
  •  闹比i
    闹比i (楼主)
    2021-02-04 03:25

    It will work correctly on any widely used architecture (I can vouch for x86, PPC, ARM). The compiler will not be able to reduce it to a noop unless the function is inlined.

提交回复
热议问题