• 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: Arc: Switch case is in protected scope
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Arc: Switch case is in protected scope


  • Subject: Re: Arc: Switch case is in protected scope
  • From: ChanMaxthon <email@hidden>
  • Date: Tue, 22 Oct 2013 15:57:24 +0800

This problem comes from C variable scopes regarding braces. For most cases it is just fine but for switch() all cases are in the same scope, jumping around. ARC inserts code at beginning and end of scopes (mini stack frames here) so if a new ARC variable is defined in switch() it gets confused.

Sent from my iPhone

> On 2013年10月22日, at 15:41, "Gerriet M. Denkmann" <email@hidden> wrote:
>
> Converting to Arc (Xcode 5.0).
>
> This works fine without Arc (regardless whether TRIGGER_ERROR is defined or not):
>
> NSMutableString *mus = [ NSMutableString string ];
> NSString *word = @"abc";
>
> switch( self.colourType )
> {
>    case colour_link:
>        [ mus appendString: @"<a href=\"" ];
>        #define    TRIGGER_ERROR
>        #ifdef        TRIGGER_ERROR
>        NSString *urlStr = [ word stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding ];
>        [ mus appendString: urlStr ];
>        #else    //    no_ERROR
>        [ mus appendString: [ word stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding ] ];
>        #endif    //    no_ERROR
>
>        break;
>
>    default:
>        [ mus appendString: word ];
> };
>
> But with Arc, if TRIGGER_ERROR is defined, I get an error: "Switch case is in protected scope" with the further explanation: "Jump bypasses initialization of retaining variable".
>
>
> Was the old (non-arc) code faulty (but the compiler did not notice this)?
> Why is the arc-version (with TRIGGER_ERROR defined) wrong?
>
> Gerriet.
>
>
> _______________________________________________
>
> 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

_______________________________________________

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: 
 >Arc: Switch case is in protected scope (From: "Gerriet M. Denkmann" <email@hidden>)

  • Prev by Date: Re: Helping Arc with: "PerformSelector may cause a leak because its selector is unknown"
  • Next by Date: Re: Arc: Switch case is in protected scope
  • Previous by thread: Re: Arc: Switch case is in protected scope
  • Next by thread: Re: Arc: Switch case is in protected scope
  • Index(es):
    • Date
    • Thread