typedef struct {
//字段
int x, y;
char name[16];
//位域只占一位
bool visible : 1;
} ColorPoint;
//C 没有属性:函数在设置字段之前先检查值
void setX(ColorPoint *p, int x) {
p->x = x < 0 ? 0 : x;
}
ColorPoint point = {1, 2, "start", true};
point.y = 5;
setX(&point, -3);
//point.x is 0
//point.y is 5
//point.name is "start"
//point.visible is true
printf("point.x is %d\n", point.x);
printf("point.y is %d\n", point.y);
printf("point.name is %s\n", point.name);
printf("point.visible is %s\n", point.visible ? "true" : "false");