• 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: "jump to label crosses initialization of..."
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: "jump to label crosses initialization of..."


  • Subject: Re: "jump to label crosses initialization of..."
  • From: Clark Cox <email@hidden>
  • Date: Thu, 16 Jun 2005 07:03:43 -0400

On 6/15/05, Tim Conkling <email@hidden> wrote:
> I'm moving a C++ (CFM) project over from CodeWarrior 9.5 to Xcode
> 2.1. gcc is complaining about the following code:
>
>      #ifdef LUA_DEBUG
>
>      if(0 != lua_gettop(L))
>          goto HandleErr;
>
>      #endif
>
>      ...
>      const DoubleRect& pos = curSprite->getPos();
>      ...
>
>      #ifdef LUA_DEBUG
>
>      HandleErr:
>      lua_stringerror(L, "GetPosition expects 0 arguments");
>
>      return 0;
>
>      #endif
>
> The error messages (there are three) are:
>
> LuaSpriteInterface.cpp:1205: error: jump to label 'HandleErr'
> LuaSpriteInterface.cpp:1186: error:   from here
> LuaSpriteInterface.cpp:1194: error:   crosses initialization of
> 'const DoubleRect& pos'
>
>
> Am I doing something non-standard here?

Yes, anytime you use goto to jump into the lifetime of an automatic
variable. That is, you jump to a point after the object is
initialized, but before it is goes out of scope, thereby not allowing
the constructor to be called (or in this case, the reference to be
initialized), you've invoked undefined behavior.

> How can I fix it?

You can make sure the the offending object's lifetime does not contain
the label; like so:

...
goto label;
...

{ //Notice braces
  const DoubleRect& pos = curSprite->getPos();
  ...
}

...
label:
...


> I would
> like to continue using goto: as this problem occurs in many places in
> my code.


--
Clark S. Cox III
email@hidden
http://www.livejournal.com/users/clarkcox3/
http://homepage.mac.com/clarkcox3/
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >"jump to label crosses initialization of..." (From: Tim Conkling <email@hidden>)

  • Prev by Date: XCode 2.1 dependency and indexer issues
  • Next by Date: Re: Predefined compiler symbols
  • Previous by thread: Re: "jump to label crosses initialization of..."
  • Next by thread: Multiple projects - can they share the same project folder?
  • Index(es):
    • Date
    • Thread