Combining Enum Value using Bitmask

前端 未结 4 616
离开以前
离开以前 2021-02-09 02:29

I understand it\'s possible to use bitmasks in enum values, but I don\'t know how to create it.

I have a simple enum :

enum State
{
    minimizing = 0,
          


        
4条回答
  •  走了就别回头了
    2021-02-09 03:07

    I just tried this in VS2012, the optimizer seems to correctly combine bits without any need for assistance if you're using bitfields.

    struct BITS { int x: 1; int y:1; };
    

    then

    BITS b;
    b.x = b.y = 1;
    

    Sets both bits with one instruction.

提交回复
热议问题