1
0

09_debugmacro.c 667 B

1234567891011121314151617181920212223242526272829303132333435
  1. #include <stdio.h>
  2. #define IS_DEBUG
  3. #define printnum(x) printf("%d\n", x)
  4. #ifdef IS_DEBUG
  5. #define readnum(x) \
  6. { \
  7. printf("Reading number with scanf(%%d)\n"); \
  8. scanf("%d", &x); \
  9. }
  10. #else
  11. #define readnum(x) scanf("%d", &x)
  12. #endif
  13. #if defined(IS_DEBUG) && !defined(debuginit)
  14. void debuginit()
  15. {
  16. printf("Running in debug mode, disable this by commenting out #define "
  17. "IS_DEBUG\n");
  18. }
  19. #endif
  20. int main()
  21. {
  22. #ifdef IS_DEBUG
  23. debuginit();
  24. #endif
  25. printf("Enter some number:\n");
  26. int x;
  27. readnum(x);
  28. printf("Number was ");
  29. printnum(x);
  30. return 0;
  31. }