Why use the Bitwise-Shift operator for values in a C enum definition?

前端 未结 8 1306
眼角桃花
眼角桃花 2020-12-02 10:42

Apple sometimes uses the Bitwise-Shift operator in their enum definitions. For example, in the CGDirectDisplay.h file which is part of Core

8条回答
  •  清歌不尽
    2020-12-02 11:09

    If you have FlagA=1, FlagB=2 and FlagC=3, FlagA or FlagB would give the same value as FlagC. The shift operator is used to ensure that every combination of flags is unique.

提交回复
热议问题