code_junkie

How do you use #define?

Nov 10th, 2011
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. static void Main(string[] args)
  2. {
  3. #if DEBUG
  4. //this only compiles if in DEBUG
  5. Console.WriteLine("DEBUG")
  6. #endif
  7. #if !DEBUG
  8. //this only compiles if not in DEBUG
  9. Console.WriteLine("RELEASE")
  10. #endif
  11. //This always compiles
  12. Console.ReadLine()
  13. }
  14.  
  15. #if definied(DEBUG)
  16. #define DEBUGLOG(message) printf("%s",message);
  17. #else
  18. #define DEBUGLOG(message)
  19. #end if
  20.  
  21. #if defined(DEBUG)
  22. #undef DEBUG
  23. #endif
  24.  
  25. #include <stdio.h>
  26.  
  27. #define PI 3.141592654
  28.  
  29. int main() {
  30. printf("%fn", PI);
  31. }
  32.  
  33. #define PRINT(x) printf("%sn", (x))
  34. /* Then you could say PRINT("Hello, world.n"); and it would
  35. * be replaced with printf("%sn", "Hello, Worldn");
  36. */
  37.  
  38. #ifdef linux
  39. /* if linux is defined, this will be compiled. It will be left out if not. */
  40. #endif
  41.  
  42. #if 0
  43. /* This code will never be included for compilation. */
  44. #endif
  45.  
  46. #define USEFOREACH
  47.  
  48. #if USEFOREACH
  49. foreach(var item in items)
  50. {
  51. #else
  52. for(int i=0; i < items.Length; ++i)
  53. { var item = item[0];
  54. #endif
  55.  
  56. doSomethingWithItem(item);
  57. }
  58.  
  59. #define PLAYSOUNDS
  60.  
  61. #ifdef PLAYSOUNDS
  62. // Do lots of funk to play a sound
  63. return true;
  64. #else
  65. return true;
Add Comment
Please, Sign In to add comment