在c语言中,枚举类型 与 int类型一样,是4个字节。可以把enum类型看成特殊的int型数据
-
gwwu@hz-dev2.wgw.com:~/test/enum>more bool.c
-
#include <stdio.h>
-
#include <stdlib.h>
-
enum wgw {a,b,c};
-
typedef enum { ah_false = 0,ah_true = 1} ah_bool_t;
-
int main(int argc,char *argv)
-
{
-
ah_bool_t a;
-
printf("sizeof(enum wgw)=%d,sizeof(ah_bool_t)=%d\n",sizeof(enum wgw),sizeof(ah_bool_t));
-
a = 2;
-
printf("a=%d,sizeof(a)=%d\n",a,sizeof(a));
-
a = -5;
-
printf("a=%d\n",a);
-
return 0;
-
}
编译运行:
-
gwwu@hz-dev2.wgw.com:~/test/enum>gcc -g bool.c -o bool
-
gwwu@hz-dev2.wgw.com:~/test/enum>./bool
-
sizeof(enum wgw)=4,sizeof(ah_bool_t)=4
-
a=2,sizeof(a)=4
-
a=-5
阅读(4127) | 评论(0) | 转发(0) |