Inicio > Programación, Resolución problemas > Gcc: Cruza la inicialización de …

Gcc: Cruza la inicialización de …

Martes, 2 de diciembre de 2008 Dejar un comentario Ir a comentarios

buf … hasta que uno se acostumbra a todos los errores y advertencias que te suelta gcc pasa mucho tiempo, y es que acaba de darme uno de esos errores que no sabes que solución puede tener, ya que la solución dista mucho de lo que uno podría imaginarse en un principio. El error que me daba era algo como esto dentro de un case de un bloque switch:

../src/octree.tcc:833: error: salto a la etiqueta case
../src/octree.tcc:823: error:   cruza la inicialización de ‘const guoctree::Octree<guoctree::octreeValues, 1>::Aggregate* aa’

Si te ha ocurrido algo como esto alguna vez sigue leyendo para averiguar como solucionar el problema.

La razón es que hay una declaración de un objeto o variable sin ámbito (sccope). Por lo tanto, el ámbito del objeto podría atravesar la sentencia break y aplicarse al siguiente case. Esto generalmente se da cuando inicializamos algún objeto mediante su constructor y no delimitamos cada case con llaves o brackets. Por lo tanto la solución es bien sencilla os dejo a continución mi trozo de código que fallaba:

case AggregateNode:
        const Aggregate *a = reinterpret_cast < const Aggregate * >(node);
        if (a->value(0,0,0) == OV_BLACK)
        {
          out << "Shape { \n"
               << "appearance Appearance { material Material { diffuseColor 0.6 0.35 0.0 } }\n"
               << "geometry Box { size 1.0 1.0 1.0 }\n"
               << "},\n";
        }
        break;

Y ahora el misco trozo de código corregido (delimitado por llaves):

case AggregateNode:
   {
        const Aggregate *a = reinterpret_cast < const Aggregate * >(node);
        if (a->value(0,0,0) == OV_BLACK)
        {
          out << "Shape { \n"
               << "appearance Appearance { material Material { diffuseColor 0.6 0.35 0.0 } }\n"
               << "geometry Box { size 1.0 1.0 1.0 }\n"
               << "},\n";
        }
   }
   break;

Por lo tanto os aconsejo que os acostumbréis a escribir vuestros bloques de código switch con brackets siempre que os acordéis ;-).

buf … Until you get used to all errors and warnings that gcc throw, much time is spent. Recently gcc show me one of this errors with difficult explanation, and its solution are far from one could imagine in first instance. The error which gcc show me about a line code inside a switch block code is:

../src/octree.tcc:833: error: jump to case label
../src/octree.tcc:823: error:   crosses initialization of ‘const guoctree::Octree<guoctree::octreeValues, 1>::Aggregate* aa’

If you ever had some error like this, continue reading this post to find out how to solve the problem.

The reason for this problem is that there is a declaration of an object or variable without scope. Thus, the scope of the object could traverse the break statement and apply to the next case. This case appears generally when we initialize some object through its constructor and don’t delimit each case statement with brackets. Therefore the solution is very easy, we only must enclose all the cases whit brackets to avoid problems. Now, you can see the wrong code below:

case AggregateNode:
        const Aggregate *a = reinterpret_cast < const Aggregate * >(node);
        if (a->value(0,0,0) == OV_BLACK)
        {
          out << "Shape { \n"
               << "appearance Appearance { material Material { diffuseColor 0.6 0.35 0.0 } }\n"
               << "geometry Box { size 1.0 1.0 1.0 }\n"
               << "},\n";
        }
        break;

And after applying the solution this is the code:

case AggregateNode:
   {
        const Aggregate *a = reinterpret_cast < const Aggregate * >(node);
        if (a->value(0,0,0) == OV_BLACK)
        {
          out << "Shape { \n"
               << "appearance Appearance { material Material { diffuseColor 0.6 0.35 0.0 } }\n"
               << "geometry Box { size 1.0 1.0 1.0 }\n"
               << "},\n";
        }
   }
   break;

I suggest that you get used to write all case statements with brackets ;) .

GD Star Rating
loading...
Gcc: Cruza la inicialización de ..., 10.0 out of 10 based on 2 ratings
Share
  1. nnarayann
    Miércoles, 4 de marzo de 2009 a las 14:29 | #1
    GD Star Rating
    loading...

    Muchas gracias, me ha sido de gran ayuda!!

    Un saludo.

  2. caio
    Lunes, 28 de septiembre de 2009 a las 19:39 | #2
    GD Star Rating
    loading...

    Grande, me solucionaste, hace media hora que estoy trabad en eso, gracias!!!!

  3. Ricardo
    Miércoles, 28 de octubre de 2009 a las 00:50 | #3
    GD Star Rating
    loading...

    Ahhhhh gracias, yo llevaba ya 1 hora, y no creo q hubiera podido resolverlo por mi, gracias

  4. miriam
    Jueves, 12 de noviembre de 2009 a las 20:16 | #4
    GD Star Rating
    loading...

    Gracias…. me sacaste de un gran apuro tenia como dos horas con este error….

  5. Toni
    Domingo, 6 de diciembre de 2009 a las 21:18 | #5
    GD Star Rating
    loading...

    Joooder, muuuuchas graciass!!! desde luego….no se me olvidarán nunca más las llaves…jeje. Saludoss

  1. Sin trackbacks aún.