Declare variables at top of function or in separate scopes?

后端 未结 9 1142
温柔的废话
温柔的废话 2020-12-01 01:47

Which is preferred, method 1 or method 2?

Method 1:

LRESULT CALLBACK wpMainWindow(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
    switch (         


        
9条回答
  •  天涯浪人
    2020-12-01 02:14

    You can't know at what point the stack reservation is done.

    For readability I would go with C99 (or C++). That allows you the declaration of a variable really there where first use it.

     HDC hdc = BeginPaint(hwnd, &ps);
    

提交回复
热议问题