title: Embedded if statement in a #define macro
body: <p>I was reading an article where #define macro was made like this:</p>
  
  <pre><code>#define TEST(level) if (level &gt; 2) ; else std::cout
  </code></pre>
  
  <p>which then could be used in the code like this:</p>
  
  <pre><code>Test(1) &lt;&lt; 3;
  Test(3) &lt;&lt; 4;
  </code></pre>
  
  <p>I was under the impression that if you wrote </p>
  
  <pre><code>TEST(1)
  </code></pre>
  
  <p>it would replace it with:</p>
  
  <pre><code>std::cout
  </code></pre>
  
  <p>and</p>
  
  <pre><code>TEST(3)
  </code></pre>
  
  <p>would be replaced with an empty string (in the code file). However, if it worked this way, then it should throw an error, since</p>
  
  <pre><code>&lt;&lt; 3;
  </code></pre>
  
  <p>is invalid.</p>
  
  <p>How does this macro actually work? and how does the pre-processor change</p>
  
  <pre><code>TEST(3) &lt;&lt; 3;
  </code></pre>
  
  <p>so that it doesn't output anything (that is, the code doesn't run)</p>