所以在我的旅行中,我经常看到枚举的定义是这样的(当需要一个位图时)

enum {
    UIControlStateNormal       = 0,
    UIControlStateHighlighted  = 1 << 0,                  // used when UIControl isHighlighted is set
    UIControlStateDisabled     = 1 << 1,
    UIControlStateSelected     = 1 << 2,                  // flag usable by app (see below)
};

不过,我最近查看了nsjsonserialization类,发现了一个这样定义的枚举
enum {
    NSJSONReadingMutableContainers = (1UL << 0),
    NSJSONReadingMutableLeaves     = (1UL << 1),
    NSJSONReadingAllowFragments    = (1UL << 2)
};
typedef NSUInteger NSJSONReadingOptions;

所以我想我的问题是UL做什么。1 << 11UL << 1之间有什么区别?

最佳答案

在C++中,UL只是表示文字是unsigned long整数类型。默认整数文字为int

10-06 02:20