Answer the question
In order to leave comments, you need to log in
How does it work: case climbed inside if'a?
I understand an example. How can I put a case branch inside an if? Unless the structural approach allows it? Or is case just a label anywhere, as long as it doesn't go beyond the boundaries of switch?
(I myself program the PLC, i.e. I only study C++)
At the request of the moderator:
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
if ( g_IsInitialized )
{
switch (message)
{
case WM_PAINT:
Update();
Render();
break;
case WM_SYSKEYDOWN:
case WM_KEYDOWN:
{
bool alt = (::GetAsyncKeyState(VK_MENU) & 0x8000) != 0;
switch (wParam)
{
case 'V':
g_VSync = !g_VSync;
break;
case VK_ESCAPE:
::PostQuitMessage(0);
break;
case VK_RETURN:
if ( alt )
{
case VK_F11: // <------------------------------
SetFullscreen(!g_Fullscreen);
}
break;
}
}
break;
// The default window procedure will play a system notification sound
// when pressing the Alt+Enter keyboard combination if this message is
// not handled.
case WM_SYSCHAR:
break;
case WM_SIZE:
{
RECT clientRect = {};
::GetClientRect(g_hWnd, &clientRect);
int width = clientRect.right - clientRect.left;
int height = clientRect.bottom - clientRect.top;
Resize(width, height);
}
break;
case WM_DESTROY:
::PostQuitMessage(0);
break;
default:
return ::DefWindowProcW(hwnd, message, wParam, lParam);
}
}
else
{
return ::DefWindowProcW(hwnd, message, wParam, lParam);
}
return 0;
}
Answer the question
In order to leave comments, you need to log in
It is possible but not necessary. In some old sish compilers, it seemed that it was even possible to switch between functions using goto. And for some reason it was used and the stack was ruled by hands to make everything work.
And this is modern C++
No warnings...
for (int i = 0; i < 10; ++i) {
for_label:;
cout << i << endl;
}
goto for_label;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question