title: Are constant C expressions evaluated at compile time or at runtime?
body: <p>If I write a <em>#define</em> that performs an operation using other preprocessor constants, is the final value computed each time the macro appears at runtime? Does this depend on optimizations in the compiler, or is it covered under a standard?</p>
  
  <p>Example:</p>
  
  <pre><code>#define EXTERNAL_CLOCK_FREQUENCY    32768
  #define TIMER_1_S                   EXTERNAL_CLOCK_FREQUENCY
  #define TIMER_100_MS                TIMERB_1_S / 10
  </code></pre>
  
  <p>Will the operation <em>32768 / 10</em> occur at runtime every time I use the TIMER_100_MS macro?</p>
  
  <p>I would like to avoid the following:</p>
  
  <pre><code>#define EXTERNAL_CLOCK_FREQUENCY    32768
  #define TIMER_1_S                   EXTERNAL_CLOCK_FREQUENCY
  #define TIMER_100_MS                3276
  </code></pre>
  
  <hr>
  
  <h3>Summary</h3>
  
  <p>A compiler is required to be able to evaluate constant integral expressions because they are necessary for calculating things like array sizes at compile time. However, the standard only says they "can" -- not "must" -- do so. Therefore, only a brain-dead compiler would not evaluate a constant integral expressions at compile time, but a simple check of the assembly output for an unconventional compiler would verify each case.</p>