0

I was trying to enumerate filetypes with bitmasking for fast and easy distinguishing on bitwise OR:

typedef enum {

    FileTypeDirectory = 1,
    FileTypePIX = 2,
    FileTypeJPG = 4,
    FileTypePNG = 8,
    FileTypeGIF = 16,
    FileTypeHTML = 32,
    FileTypeXML = 64,
    FileTypeTXT = 128,
    FileTypePDF = 256,  
    FileTypePPTX = 512,

    FileTypeAll = 1023

} FileType;

My OR operations did work until 128, afterwards it failed. Are enums on a 64 Bit Mac OSX limited to Byte Datatypes? (2^7=128)

Michael A
  • 9,480
  • 22
  • 70
  • 114
Low Noise
  • 3
  • 1

2 Answers2

0

All enum constants in C are of type int and not of the type of the enumeration itself. So the restriction is not in the storage size for enum variables, but only in the number of bits for an int.

I don't know much of objective-c (as this is tagged also) but it shouldn't deviate much from C.

Jens Gustedt
  • 76,821
  • 6
  • 102
  • 177
0

I'm not quite sure how you used the OR operator but it works for me well with your typedef.

FileType _fileType = FileTypeGIF | FileTypePDF | FileTypePPTX;
NSLog(@"filetype is : %d", _fileType);

the result is:

filetype is : 784

which is correct values because 16 + 256 + 512 is precisely 784.


(it has been tested on real device only.)

holex
  • 23,961
  • 7
  • 62
  • 76