Will bit-shift by zero bits work correctly?

后端 未结 6 921
轮回少年
轮回少年 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条回答
  •  被撕碎了的回忆
    2021-02-04 03:21

    To make the function somewhat self documenting, you may want to change bitCount to unsigned to signify to callers that a negative value is not valid.

提交回复
热议问题