• 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
Proper switching and casing.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Proper switching and casing.


  • Subject: Proper switching and casing.
  • From: Alex Zavatone <email@hidden>
  • Date: Thu, 09 Apr 2015 16:53:49 -0400

I'm looking through the new code that I've inherited and getting to know and love it and I'm running across a few new circumstances I've never seen before.

With that said, I just noticed a switch statement with empty case conditions where the variable being checked will be 0, and the execution point/program counter hits both the case statement for 0 and for 1.

It looks something like this:

switch (myObject.myInt) {

    case 0:
        {
            // There is no code at all within these parens.  This is empty.
        }

    case 1:
        {
            // Important stuff happens here
        }
            break;

    case 2:
        {
            // More important stuff happens here
        }
            break;

        default:
            break;
    }

I was really surprised as all our code within case 1 was getting executed when myInt == 0 and when myInt == 1.   Then I noticed that case:0 was put in for a placeholder condition.  Since it was entered as a placeholder, it was entered without a break statement after it.  In the case of myInt == 0, the program execution just continued down into the case of 1 code block and happily executed it.

Who says learning new code isn't fun?

Cheers,
Alex




_______________________________________________

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


  • Follow-Ups:
    • Re: Proper switching and casing.
      • From: Alex Zavatone <email@hidden>
  • Prev by Date: Re: Does GCD auto-limit concurrent tasks to number of cores?
  • Next by Date: Re: Proper switching and casing.
  • Previous by thread: Re: Does GCD auto-limit concurrent tasks to number of cores?
  • Next by thread: Re: Proper switching and casing.
  • Index(es):
    • Date
    • Thread