Re: "jump to label crosses initialization of..."
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