title: Using SDL_PollEvent vs SDL_PumpEvents
body: <p>I've been using SDL for a while now, but now it seems I've been doing things the wrong way when working with keyboard events.</p>
  
  <p>Normally my main loop looks something like this:</p>
  
  <pre class="lang-cpp prettyprint-override"><code>int main() {
      SDL_Init(SDL_INIT_VIDEO);
      /* Some video system initializations */
  
      /* Main loop */
      for(;;) {
          SDL_PumpEvents();
          const unsigned char *key = SDL_GetKeyboardState(nullptr);
  
          /* Do something with the keys pressed */
      }
  }
  </code></pre>
  
  <p>... and this has worked fine for me. But I've recently looked at some code examples, and technically all of them use a different pattern:</p>
  
  <pre class="lang-cpp prettyprint-override"><code>int main() {
      SDL_Init(SDL_INIT_VIDEO);
      /* Some video system initializations */
  
      /* Main loop */
      for(;;) {
          SDL_Event event;
          while (SDL_PollEvent(&amp;event)) {
              /* switch/case to know keys pressed */
          }
      }
  }
  </code></pre>
  
  <p>So looking at SDL documentation I found that <code>SDL_PollEvent</code> does call <code>SDL_PumpEvents</code>. <a href="https://wiki.libsdl.org/SDL_PollEvent?highlight=%28%5CbCategoryEvents%5Cb%29%7C%28CategoryEnum%29%7C%28CategoryStruct%29" rel="nofollow noreferrer">SDL_PollEvent reference</a></p>
  
  <p>And what <code>SDL_PumpEvents</code> does is to gather the state of all input devices to generate event objets. <a href="https://wiki.libsdl.org/SDL_PumpEvents?highlight=%28%5CbCategoryEvents%5Cb%29%7C%28CategoryEnum%29%7C%28CategoryStruct%29" rel="nofollow noreferrer">SDL_PumpEvents reference</a></p>
  
  <p>So in the first example, I'm not <em>flushing</em> the event queue, so why does it works without crashing? Is the second pattern the <em>correct</em> way of getting input state?</p>