Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- char *str[] = { "bit 0", "bit 1", "bit 2", "bit 3", "bug" };
- static inline int __next_bit(unsigned int active_bases, int bit)
- {
- do {
- if (active_bases & (1 << bit))
- return bit;
- } while (++bit < 4);
- printf("BUG\n");
- /* We should never reach here */
- return 0;
- }
- #define for_each_active_base(_bit, _base, _cpu_base, _active_bases) \
- for ((_active_bases) = active_bases, _bit = -1; \
- (_active_bases) && \
- ((_bit) = __next_bit(_active_bases, ++_bit), \
- (_base) = (_cpu_base) + _bit); \
- (_active_bases) &= ~(1 << (_bit)))
- void main (void)
- {
- unsigned int active_bases, active_bases1;
- int bit;
- char **base;
- printf("Enter number\n");
- scanf("%u", &active_bases);
- for_each_active_base(bit, base, str, active_bases1)
- printf("%s\n", *base);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement