What is the difference between these two listings?

Thus, in my travels, I saw how such transfers are listed (when a bit map is required)

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

However, I recently looked at the NSJSONSerilization class to meet an enumeration defined as

enum {
    NSJSONReadingMutableContainers = (1UL << 0),
    NSJSONReadingMutableLeaves     = (1UL << 1),
    NSJSONReadingAllowFragments    = (1UL << 2)
};
typedef NSUInteger NSJSONReadingOptions;

So, I think my question is what it does UL. What is the difference between 1 << 1and1UL << 1

+3
source share
4 answers

In C ++, ULjust means that a literal is an integer type unsigned long. Integer default literal int.

+5
source

1 << 1 1UL << 1, 1 << 33 1UL << 33. unsigned long , int, , enum , int .

+5

In practice, there is no difference in your code.

The type 1in the first is this int, and the type 1ULin the second is unsigned long.

+1
source

The code will work the same, there is no real difference.

However, the type is 1in the first code int, while the type is 1ULin the second code unsigned long.

+1
source

All Articles