I'm reading through a library and found an enumeration that looks like this:
typedef enum
{
IS_SYNCED = 0; //Determines if device is in/out of sync
IS_VALID_REF = 1; //Determines if device reference is valid
} EVENT;
I'm wondering how the to check what the value of IS_SYNCED
would be?
You can compare enum values with ==
.
EVENT e = IS_SYNCED;
if(e == IS_SYNCED)
printf("Is synced event\n");
else if(e == IS_VALID_REF)
printf("Is valid ref event\n");
else
printf("Unknown event\n");
prints:
Is synced event
You can also use switch
:
EVENT e = IS_SYNCED;
switch(e) {
case IS_SYNCED:
printf("Is synced event\n");
break;
case IS_VALID_REF:
printf("Is valid ref event\n");
break;
default:
printf("Unknown event\n");
break;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.