1 #include
2
3 /*
4 * +---+---+---+---+---+---+---+---+5 * |8th|7th|6th|5th|4th|3rd|2nd|1st|6 * +---------------+---+---+---+---+---+---+---+---+7 * | INDEX | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |8 * +---------------+---+---+---+---+---+---+---+---+9 * | SF_ATTENTION | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 |10 * | SF_INPROGRESS | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 |11 * | SF_OK | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 |12 * | SF_ERR | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 |13 * | SF_TIMEOUT | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 |14 * | SF_USYNC | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 |15 * | SF_XXX | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 |16 * | SF_YYY | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |17 * +---------------+---+---+---+---+---+---+---+---+18 */
19
20 #define SF_ATTENTION 001 /* entry needs servicing */
21 #define SF_INPROGRESS 002 /* sync is in progress */
22 #define SF_OK 004 /* sync has happend successfully */
23 #define SF_ERR 010 /* sync has happend unsuccessfully */
24 #define SF_TIMEDOUT 020 /* proc timed out in sync event */
25 #define SF_USYNC 040 /* entry is a user sync, else auto */
26
27 /**28 * OR (2) define as (1 << N):29 *30 * #define SF_ATTENTION (1 << 0)31 * #define SF_INPROGRESS (1 << 1)32 * #define SF_OK (1 << 2)33 * #define SF_ERR (1 << 3)34 * #define SF_TIMEDOUT (1 << 4)35 * #define SF_USYNC (1 << 5)36 *37 * OR (3) define as Hex:38 *39 * #define SF_ATTENTION 0x0140 * #define SF_INPROGRESS 0x0241 * #define SF_OK 0x0442 * #define SF_ERR 0x0843 * #define SF_TIMEDOUT 0x1044 * #define SF_USYNC 0x2045 */
46
47 /*
48 * If there is an int flags, we want to clear its specified bits to be zero,49 * we will use50 * flags &= ~(... | ... | ...)51 *52 * e.g. clear the 3rd, 4th and 5th bits to be 053 * flags &= ~(SF_OK | SF_ERR | SF_TIMEDOUT);54 */
55
56 /*
57 * XXX: _NOTE is from /usr/include/sys/note.h of Solaris58 * note.h: interface for annotating source with info for tools59 */
60 #ifndef _NOTE61 #define _NOTE(s)
62 #endif
63
64 int
65 main(int argc, char *argv[])66 {67 unsigned char flags = SF_ATTENTION | SF_OK |SF_USYNC;68 _NOTE( 87654321)69 _NOTE( --------)70 _NOTE(flags == 045 ==00100101b)71 printf("a) flags = 0%o\n", flags);72
73 _NOTE(flags &= ~(bit#3 | bit#4 | bit#5))74 flags &= ~(SF_OK | SF_ERR |SF_TIMEDOUT);75
76 _NOTE( 87654321)77 _NOTE( --------)78 _NOTE(flags == 041 ==00100001b)79 printf("b) flags = 0%o\n", flags);80
81 returnflags;82 }