Advertisement
Guest User

Untitled

a guest
Apr 3rd, 2015
238
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2.  
  3. char *str[] = { "bit 0", "bit 1", "bit 2", "bit 3", "bug" };
  4.  
  5. static inline int __next_bit(unsigned int active_bases, int bit)
  6. {
  7. do {
  8. if (active_bases & (1 << bit))
  9. return bit;
  10. } while (++bit < 4);
  11.  
  12. printf("BUG\n");
  13. /* We should never reach here */
  14. return 0;
  15. }
  16.  
  17. #define for_each_active_base(_bit, _base, _cpu_base, _active_bases) \
  18. for ((_active_bases) = active_bases, _bit = -1; \
  19. (_active_bases) && \
  20. ((_bit) = __next_bit(_active_bases, ++_bit), \
  21. (_base) = (_cpu_base) + _bit); \
  22. (_active_bases) &= ~(1 << (_bit)))
  23.  
  24. void main (void)
  25. {
  26. unsigned int active_bases, active_bases1;
  27. int bit;
  28. char **base;
  29.  
  30. printf("Enter number\n");
  31. scanf("%u", &active_bases);
  32.  
  33. for_each_active_base(bit, base, str, active_bases1)
  34. printf("%s\n", *base);
  35. }
Advertisement
RAW Paste Data Copied
Advertisement