enum type check in C/gcc

前端 未结 6 963
小鲜肉
小鲜肉 2020-12-03 03:19

See the simple example below. When a function returning one enum is assigned to a variable of a different enum I don\'t get any warning even with <

6条回答
  •  萌比男神i
    2020-12-03 03:48

    An enum in C is basically handled like an integer. It's just a nicer way to use constants.

      // this would work as well
      ftype = 1;
    

    You can also specify the values:

      enum color {
         RED=0,GREEN,BLUE
      } mycolor;
    
      mycolor = 1; // GREEN
    

提交回复
热议问题