c, obj c enum without tag or identifier

后端 未结 3 1601
太阳男子
太阳男子 2021-01-17 06:09

im learning cocos2d [open gl wrapper for objective C on iPhone], and now playing with sprites have found this in a example,

 enum {  
easySprite =   0x000000         


        
3条回答
  •  终归单人心
    2021-01-17 06:48

    Enums are automatically assigned values, incremented from 0 but you can assign your own values.

    If you don't specify any values they will be starting from 0 as in:

    typedef enum {
     JPG,
     PNG,
     GIF,
     PVR
     } kImageType;
    

    But you could assign them values:

    typedef enum {
     JPG = 0,
     PNG = 1,
     GIF = 2,
     PVR = 3
     } kImageType;
    

    or even

    typedef enum {
     JPG = 100,
     PNG = 0x01,
     GIF = 100,
     PVR = 0xff
     } kImageType;
    

    anything you want, repeating values are ok as well.

    I'm not sure why they are given those specific values but they might have some meaning related to use.

提交回复
热议问题