• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Proper switching and casing.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Proper switching and casing.


  • Subject: Re: Proper switching and casing.
  • From: Sean McBride <email@hidden>
  • Date: Thu, 09 Apr 2015 17:39:03 -0400
  • Organization: Rogue Research Inc.

On Thu, 9 Apr 2015 16:33:36 -0500, Steve Mills said:

>On Apr 9, 2015, at 16:05:57, Alex Zavatone <email@hidden> wrote:
>>
>> Is there any reasonable case where you'd want a case condition to not
>have a break statement after it?
>
>Sure, and it happens a lot:
>
>switch(justification) {
>	case kLeft:
>	case kCenter:
>	case kRight:
>		DoRegularReflow();
>		break;

The lack any any statements between the cases here means -Wimplicit-fallthrough won't warn.  As you say, it's a common pattern.

>If I ever have a case that has code AND falls through, I make sure I
>mark it as such in lieu of a break:
>
>case 0:
>	Something();
>	break;
>case 1:
>	printf("Hey, it's doing that thing you wanted to know about.\n");
>	// Fall through!
>case 2: {
>	NSString*		s = [self getString];
>
>	Blah(s);
>	break;

Under C++11 you could use [[clang::fallthrough]]:

<http://clang.llvm.org/docs/AttributeReference.html#fallthrough-clang-fallthrough>

Cheers,

--
____________________________________________________________
Sean McBride, B. Eng                 email@hidden
Rogue Research                        www.rogue-research.com
Mac Software Developer              Montréal, Québec, Canada



_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


References: 
 >Proper switching and casing. (From: Alex Zavatone <email@hidden>)
 >Re: Proper switching and casing. (From: Alex Zavatone <email@hidden>)
 >Re: Proper switching and casing. (From: Steve Mills <email@hidden>)

  • Prev by Date: Re: Proper switching and casing.
  • Next by Date: Re: Proper switching and casing.
  • Previous by thread: Re: Proper switching and casing.
  • Next by thread: Re: Proper switching and casing.
  • Index(es):
    • Date
    • Thread