title: C++ What is the earliest undefined behavior can manifest itself?
body: <p>I'm aware that undefined behavior can potentially cause anything, which makes any program containing UB potentially meaningless. I was wondering if there is any way to identify the earliest point in a program that undefined behavior could cause problems.
  Here is an example to illustrate my question.  </p>
  
  <pre><code>void causeUndefinedBehavior()
  {
     //any code that causes undefined behavior
     //every time it is run
     char* a = nullptr;
     *a;
  }
  
  
  int main()
  {
   //code before call
   //...
   causeUndefinedBehavior();
   //code after call
   //...
  }
  </code></pre>
  
  <p>From my understanding, the possible times undefined behavior could be evoked (not necessarily manifested) are:</p>
  
  <ol>
  <li>When <code>causeUndefinedBehavior()</code> is compiled.</li>
  <li>When <code>main()</code> is compiled.</li>
  <li>At the time the program is run.</li>
  <li>At the time <code>causeUndefinedBehavior()</code> is executed.</li>
  </ol>
  
  <p>Or is the point where undefined behavior is evoked completely different for every case and every implementation?</p>
  
  <p>In addition, if I commented out the line where <code>causeUndefinedBehavior()</code> is called, would that eliminate the UB, or would it still be in the program since code containing UB was compiled?</p>