User forums > Using Code::Blocks
Why the brackets in case in defaultcode?
(1/1)
jmb:
Hi
I wonder, why the switch in the "win32 GUI projct"-Template looks like this:
--- Code: --- switch(uMsg)
{
case WM_INITDIALOG:
{
// Code
}
return TRUE;
}
return FALSE;
--- End code ---
And so this indentation is a bit confusing.
It should rather look like this:
--- Code: ---
switch(uMsg)
{
case WM_INITDIALOG:
// Code
return TRUE;
}
return FALSE;
--- End code ---
Is there a reason for that format ?
oBFusCATed:
It is a template, not a mandatory thing.
You can change it however you like.
jmb:
Thx for answering. I just saw such "syntax" the first time and was
a bit astounded.
BlueHazzard:
normally you use the brackets in the case for scope separation...
So you can use variable i in case 0 and case 1...
see the example:
--- Code: ---switch(cnt)
{
case 1:
{
int tmp = 22;
}
break;
case 2:
{
int tmp = 33;
}
break;
}
--- End code ---
without brackets you would get the redefinition error...
greetings
jmb:
Thank you, for opening my eyes. Usually I don't declare variables in case-segments, so I didn't
had this idea and was blind ;D
Navigation
[0] Message Index
Go to full version