define SOMETHING (1

Yes, it is. Maybe it is used for symmetry when setting values for flags:

#define FLAG_1  (1 << 0)
#define FLAG_2  (1 << 2)
#define FLAG_3  (1 << 3)
/* ... */

Don’t worry about performances, a good compiler will be able to optimize such operations.

You can combine these values as follow:

/* Flags FLAG_1, FLAG_2 and FLAG_3 are set. */
f = FLAG_1 | FLAG_2 | FLAG_3;

And testing whether a given flag is set:

/* True if FLAG_1 is set. */
if (f & FLAG_1) { /* ... */ }

Leave a Comment