What does '<<' mean in C?

前端 未结 5 1901
一生所求
一生所求 2021-01-07 08:33

what does this mean?

#define WS_RECURSIVE    (1 << 0)

I understand that it will define WS_Recursive (1 << 0) but w

5条回答
  •  情话喂你
    2021-01-07 09:08

    << computes a bitwise shift to the left. Shifting 1 to the left by 0 bits simply leaves the result as 1.

    I noticed also where you got your code from that there's also:

    #define WS_RECURSIVE    (1 << 0)
    #define WS_DEFAULT  WS_RECURSIVE
    #define WS_FOLLOWLINK   (1 << 1)
    #define WS_DOTFILES     (1 << 2)
    #define WS_MATCHDIRS    (1 << 3)
    

    That is a way of creating bit fields, where you OR (|) flags together, and AND them (&) to check if they're set.

提交回复
热议问题