PageRenderTime 40ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/www.cppreference.com/wiki/preprocessor/preprocessor_if

https://github.com/tsgates/cclookup
#! | 85 lines | 76 code | 9 blank | 0 comment | 0 complexity | d3cacba70403b12beb870459b49310c5 MD5 | raw file
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
  4. lang="en" dir="ltr">
  5. <head>
  6. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  7. <title>preprocessor:preprocessor_if</title>
  8. <meta name="generator" content="DokuWiki" />
  9. <meta name="robots" content="index,follow" />
  10. <meta name="date" content="2010-10-28T18:17:02-0700" />
  11. <meta name="keywords" content="preprocessor,preprocessor_if" />
  12. <link rel="search" type="application/opensearchdescription+xml" href="http://www.cppreference.com/wiki/lib/exe/opensearch.php" title="C++ Reference" />
  13. <link rel="start" href="../../index.html" />
  14. <link rel="contents" href="http://www.cppreference.com/wiki/preprocessor/preprocessor_if?do=index" title="Sitemap" />
  15. <link rel="alternate" type="application/rss+xml" title="Recent Changes" href="http://www.cppreference.com/wiki/feed.php" />
  16. <link rel="alternate" type="application/rss+xml" title="Current Namespace" href="http://www.cppreference.com/wiki/feed.php?mode=list&amp;ns=preprocessor" />
  17. <link rel="alternate" type="text/html" title="Plain HTML" href="http://www.cppreference.com/wiki/_export/xhtml/preprocessor/preprocessor_if" />
  18. <link rel="alternate" type="text/plain" title="Wiki Markup" href="http://www.cppreference.com/wiki/_export/raw/preprocessor/preprocessor_if" />
  19. <link rel="canonical" href="preprocessor_if" />
  20. <link rel="stylesheet" media="screen" type="text/css" href="../lib/exe/css.php@t=custom1&amp;tseed=1289693594" />
  21. <link rel="stylesheet" media="all" type="text/css" href="../lib/exe/css.php@s=all&amp;t=custom1&amp;tseed=1289693594" />
  22. <link rel="stylesheet" media="print" type="text/css" href="../lib/exe/css.php@s=print&amp;t=custom1&amp;tseed=1289693594" />
  23. <script type="text/javascript" ><!--//--><![CDATA[//><!--
  24. var NS='preprocessor';var JSINFO = {"id":"preprocessor:preprocessor_if","namespace":"preprocessor"};
  25. //--><!]]></script>
  26. <script type="text/javascript" charset="utf-8" src="../lib/exe/js.php@tseed=1289693594" ></script>
  27. </head>
  28. <body>
  29. <div class="dokuwiki export">
  30. <h2 class="sectionedit1"><a name="preprocessor_conditionals" id="preprocessor_conditionals">Preprocessor Conditionals</a></h2>
  31. <div class="level2">
  32. <pre class="cpp code cpp"><span class="co2">#if, #ifdef, #ifndef, #else, #elif, #endif</span></pre>
  33. <p>
  34. These six preprocessor commands give simple logic control to the compiler. As a file is being
  35. compiled, you can use these commands to cause certain lines of code to be
  36. included or not included.
  37. </p>
  38. <pre class="cpp code cpp"> <span class="co2">#if expression</span></pre>
  39. <p>
  40. If the value of expression is true, then the code that immediately follows the
  41. command will be compiled.
  42. </p>
  43. <pre class="cpp code cpp"> <span class="co2">#ifdef macro</span></pre>
  44. <p>
  45. If the macro has been defined by a <a href="define" class="wikilink1" title="preprocessor:define">#define</a> statement, then the code immediately
  46. following the command will be compiled.
  47. </p>
  48. <pre class="cpp code cpp"> <span class="co2">#ifndef macro</span></pre>
  49. <p>
  50. If the macro has not been defined by a <a href="define" class="wikilink1" title="preprocessor:define">#define</a> statement, then the code
  51. immediately following the command will be compiled.
  52. </p>
  53. <p>
  54. A few side notes: The command #elif is simply a horribly truncated way to say
  55. elseif and works like you think it would. You can also throw in a defined
  56. or !defined after an #if to get added functionality.
  57. </p>
  58. <p>
  59. Here&#039;s an example of all these:
  60. </p>
  61. <pre class="cpp code cpp"> <span class="co2">#ifdef DEBUG</span>
  62. <span class="kw3">cout</span> <span class="sy1">&lt;&lt;</span> <span class="st0">&quot;This is the test version, i=&quot;</span> <span class="sy1">&lt;&lt;</span> i <span class="sy1">&lt;&lt;</span> endl<span class="sy4">;</span>
  63. <span class="co2">#else</span>
  64. <span class="kw3">cout</span> <span class="sy1">&lt;&lt;</span> <span class="st0">&quot;This is the production version!&quot;</span> <span class="sy1">&lt;&lt;</span> endl<span class="sy4">;</span>
  65. <span class="co2">#endif</span></pre>
  66. <p>
  67. You might notice how that second example could make debugging a lot easier than
  68. inserting and removing a million couts in your code.
  69. </p>
  70. <p>
  71. Related topics: <a href="define" class="wikilink1" title="preprocessor:define">#define</a>
  72. </p>
  73. </div>
  74. </div>
  75. </body>
  76. </html>