title: Implementing yield in C
body: <p>For example:</p>
  
  <pre><code>int getNext(int n) {
      while (TRUE) {
          n = n+1;
          yield n;
      }
  }
  
  int main() {
      while (TRUE) {
          int n = getNext(1);
          if (n &gt; 42)
             break;
          printf("%d\n",n);
      }
  }
  </code></pre>
  
  <p>Such that the above code would print all numbers from 1 to 42.
  I thought of making <code>yield</code> change the address of getNext to the instruction after <code>yield</code>. But I cant figure out how I would save the context (registers/variables) since the stack would be ran over by the caller function.</p>
  
  <p>Note:</p>
  
  <p>I realize that the code above can be easily implemented by static variables, but that's not the point.</p>