In
void foo(UINT W, UINT H)
{
// magic
{
SIZE window = {};
window.Width = W;
window.Height= H;
}
// magic
}
The extra curly braces establish a compound statement, also known as a block. In this example, this block doesn't do anything except establish the scope of window
. window
only exists within the block; as soon as the closing brace is reached, window
will be destroyed.
Side note:
The initialization of window
can be greatly simplified:
void foo(UINT W, UINT H)
{
// magic
{
SIZE window = {W,H};
}
// magic
}
This makes use of Aggregate Initialization.
Another note: Avoid using ALLCAPS identifiers for anything but constants. It can lead to unexpected macro substitutions with a previously defined constant just like this poor soul found out the hard way. In addition, single letter variables should be avoided. A single letter tends to not be descriptive enough to convey what is represented by the variable and they are very easy to accidentally mix up while also being very hard to spot when mixed up.