flag在c语言中标识某种状态或记录某种信息,可以通过修改flag中来控制程序流程,判断某种状态是否存在或记录某种信息
操作:(1)初始化 (2)赋值 (3)判断 (4)修改 (5)去初始化
#include <stdlib.h>int power_state_check;int main()
{int i = 0;power_state_check = 0x10;if(power_state_check&0x10){power_state_check |= (1<<0);}if(power_state_check&0x10){power_state_check |= (1<<1);}if(power_state_check&0x10){power_state_check |= (1<<2);}if(power_state_check&0x10){power_state_check |= (1<<3);}if(power_state_check&0x10){printf("Hello, World power_state_check is %x\n",power_state_check);for(i=0;i<4;i++){if((power_state_check&(1<<i)) == 0x0){printf("i =%d cmd loss func %s line %d\r\n",i,__func__,__LINE__);if(i==2){printf(" i=%d cmd loss func msg_match enter operation %s line %d\r\n",i,__func__,__LINE__);}}}}power_state_check = 0x0;printf("Hello, World power_state_check is %d\n",power_state_check);return(0);
}