title: Declare variables at top of function or in separate scopes?
body: <p>Which is preferred, method 1 or method 2?</p>
  
  <h3>Method 1:</h3>
  
  <pre><code>LRESULT CALLBACK wpMainWindow(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
  {
      switch (msg)
      {
          case WM_PAINT:
          {
              HDC hdc;
              PAINTSTRUCT ps;
  
              RECT rc;
              GetClientRect(hwnd, &amp;rc);           
  
              hdc = BeginPaint(hwnd, &amp;ps);
              // drawing here
              EndPaint(hwnd, &amp;ps);
              break;
          }
          default: 
              return DefWindowProc(hwnd, msg, wparam, lparam);
      }
      return 0;
  }
  </code></pre>
  
  <h3>Method 2:</h3>
  
  <pre><code>LRESULT CALLBACK wpMainWindow(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
  {
      HDC hdc;
      PAINTSTRUCT ps;
      RECT rc;
  
      switch (msg)
      {
          case WM_PAINT:
              GetClientRect(hwnd, &amp;rc);
  
              hdc = BeginPaint(hwnd, &amp;ps);
              // drawing here
              EndPaint(hwnd, &amp;ps);
              break;
  
          default: 
              return DefWindowProc(hwnd, msg, wparam, lparam);
      }
      return 0;
  }
  </code></pre>
  
  <p>In method 1, if msg = WM_PAINT when wpMainWindow function is called, does it allocate memory for all the variables on the stack at the beginning? or only when it enters the WM_PAINT scope?</p>
  
  <p>Would method 1 only use the memory when the message is WM_PAINT, and method 2 would use the memory no matter what msg equaled?</p>