Stop data retention! Click here & act! Are you a webmaster and want to participate? Here you can find all necessary material for your website - Willst du auch an der Aktion teilnehmen? Hier findest du alle relevanten Infos und Materialien:
Chris Karakas Online Forum Index Karakas Online
 FAQFAQ   Forum SearchForum Search   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
gcc error: crosses initialization of XXX



 
Post new topic   Reply to topic
   Chris Karakas Online Forum Index -> Linux Forum RSS Feed of this Forum
Share this page: These icons link to social bookmarking sites where readers can share and discover new web pages.Digg  del.icio.us  tc.eserver.org  Blinklist  Furl  Reddit  Blogmarks  Magnolia  Sphere  Yahoo!  Google  Windows Live  Technorati  Blue Dot  Simpy  Newsvine  Stumble Upon  co.mments.com  Blinkbits  BlogMemes  Connotea  View previous topic :: View next topic  
Author Message
chris
Dark Lord of the Sith


Joined: 10 May 2003
Posts: 6262
Location: Outer Space

PostPosted: Thu Mar 02, 2006 12:10 pm    Post subject: gcc error: crosses initialization of XXX
Reply with quote

Question Problem: You get an error of this form, while compiling some nice program from source:

Code:

error: jump to case label
error:   crosses initialization of `bool pushed'


The offending code contains a switch statement and a declaration of some variable or object inside one of its cases:

Code:

      case HD_ELEMENT_UL :
          bool pushed = t->style->margin[HD_POS_LEFT] != 0.0 ||
                        t->style->margin[HD_POS_RIGHT] != 0.0;

          if (pushed)
            margins->push(margins->left() + t->style->margin[HD_POS_LEFT],
                          margins->right() - t->style->margin[HD_POS_RIGHT],
                          margins->bottom(), 0);

          parse_contents(t->child, margins, y, page, heading, chap);

          if (pushed)
            margins->pop();
          break;


Idea Reason: The problem is that there is a declaration of an object (the boolean "pushed") without scope. Thus, the scope of the object could traverse the break statement and apply to the next case. Consider this - what is the scope of obj1 in the code below? It starts at the first label, and goes until the end of the case block. So it's in scope at CHOICE_B. But its constructor wasn't called....

Code:

  switch (choice) {
  case CHOICE_A:
    someclass obj1(&commonobj);

    break;
  case CHOICE_B:
    someotherclass obj2(&commonobj);

    break;
  default:
    break;
  }
}


Thus, you should use curly brackets to delimit scope, as in:

Code:

switch (choice) {
  case A: {
    someobj x;
    ...
  }
  break;
  case B: {
    ...
  }
  break;
  ...
}


Arrow Solution: Change the case statement to:

Code:

      case HD_ELEMENT_UL :
          {
          bool pushed = t->style->margin[HD_POS_LEFT] != 0.0 ||
                        t->style->margin[HD_POS_RIGHT] != 0.0;

          if (pushed)
            margins->push(margins->left() + t->style->margin[HD_POS_LEFT],
                          margins->right() - t->style->margin[HD_POS_RIGHT],
                          margins->bottom(), 0);
 
          parse_contents(t->child, margins, y, page, heading, chap);
   
          if (pushed)
            margins->pop();
          }
          break;


i.e. add curly brackets to delimit the scope of "pushed" inside the switch.

Exclamation References:

Bug#180937: g++ internal compiler error: Error reporting routines re-entered

Bug#180937: g++ internal compiler error: Error reporting routines re-entered
_________________
Regards

Chris Karakas
www.karakas-online.de
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Share this page: These icons link to social bookmarking sites where readers can share and discover new web pages.Digg  del.icio.us  tc.eserver.org  Blinklist  Furl  Reddit  Blogmarks  Magnolia  Sphere  Yahoo!  Google  Windows Live  Technorati  Blue Dot  Simpy  Newsvine  Stumble Upon  co.mments.com  Blinkbits  BlogMemes  Connotea 
Display posts from previous:   
Post new topic   Reply to topic
   Chris Karakas Online Forum Index -> Linux Forum
Page 1 of 1
This page contains valid HTML 4.01 Transitional - click here to check it!
This page contains a valid CSS - click here to check it!

 

Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group