Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 12th, 2012  |  syntax: C  |  size: 0.54 KB  |  hits: 198  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #include <stdio.h>
  2.  
  3. #define is_set(macro) is_set_(macro)
  4. #define macrotest_1 ,
  5. #define is_set_(value) is_set__(macrotest_##value)
  6. #define is_set__(comma) is_set___(comma 1, 0)
  7. #define is_set___(_, v, ...) v
  8.  
  9. #define CONFIG_FOO 1
  10. #define CONFIG_NOO 0
  11.  
  12. int main()
  13. {
  14.     printf("It's %d!\n", is_set(FOO));
  15.     if(is_set(CONFIG_FOO))
  16.     {
  17.         puts("And it's true, yo!\n");
  18.     }
  19.     if(is_set(CONFIG_NOO))
  20.     {
  21.         puts("Noooo!");
  22.     }
  23.     if(is_set(CONFIG_NOTEXIST))
  24.     {
  25.         puts("NOT EXIST");
  26.     }
  27.  
  28.     return 0;
  29. }