struct的声明和面向对象中的类还是有少许区别,现总结struct的声明的用法以备以后复习。
1 正规写法,这样便声明了一个类型struct apple:
struct apple{ ... };
struct apple{ ... }myApple;
struct { ... }myApple;
4 使用typedef,将struct apple进行重新定义类型:
typedef struct apple{ ... }apple; apple myApple;
上面的struct apple 和 apple都是指的同一个结构体类型,这里并用apple类型定义了一个变量myApple。当然这里的struct apple处的apple也可以不要。
union声明和定义变量的用法和struct是相似的。
5 enum声明很形象,并且c中还可以赋值给int类型。enum msgtype { HARD_INT = 1, /* SYS task */ GET_TICKS, DEV_OPEN = 1001, };
使用的时候直接使用就可以,比如:
int type = GET_TICKS;