Author Topic: Why the brackets in case in defaultcode?  (Read 2273 times)

Offline jmb

  • Multiple posting newcomer
  • *
  • Posts: 24
Why the brackets in case in defaultcode?
« on: July 28, 2015, 09:34:58 pm »
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;

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;



Is there a reason for that format ?



Linux Mint, Cinnamon 19.3 , Code::Blocks 20.03

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Why the brackets in case in defaultcode?
« Reply #1 on: July 28, 2015, 10:38:34 pm »
It is a template, not a mandatory thing.
You can change it however you like.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline jmb

  • Multiple posting newcomer
  • *
  • Posts: 24
Re: Why the brackets in case in defaultcode?
« Reply #2 on: July 29, 2015, 06:34:03 pm »
Thx for answering. I just saw such "syntax" the first time and was
a bit astounded.

Linux Mint, Cinnamon 19.3 , Code::Blocks 20.03

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: Why the brackets in case in defaultcode?
« Reply #3 on: July 29, 2015, 07:33:34 pm »
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;
}

without brackets you would get the redefinition error...

greetings

Offline jmb

  • Multiple posting newcomer
  • *
  • Posts: 24
Re: Why the brackets in case in defaultcode?
« Reply #4 on: July 29, 2015, 07:51:06 pm »
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


 
Linux Mint, Cinnamon 19.3 , Code::Blocks 20.03