关于Symbian的"crosses initialization of XXX"错误
来源:互联网 发布:python json的格式 编辑:程序博客网 时间:2024/06/06 08:38
昨天,同事在把前一阶段的项目编译、打包成sis安装文件时,遇到如下的编译错误 :
crosses initialization of XXX
同事向我请教,我仔细看了一下他的代码,并没有什么问题。这个错误提示很少见,于是Google了一下,找到如下一篇论坛上的资料:
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;
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;
...
}
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.
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
======================================================
注: 该资料的网址为:http://www.karakas-online.de/forum/viewtopic.php?t=4194
原来如此!问题出在case语句内定义的变量的作用域上面。只要把每个case语句用括号(" {} ")括起来,变量的作用域限定在相应case语句之内,就不会出现交叉初始化(crosses initialization )的错误,问题随之解决。
附:上面论坛资料的pdf格式文件的下载(我的box中的资源,版权归原论坛所有):
下载地址http://www.box.net/shared/ptpqtymqvz
- 关于Symbian的"crosses initialization of XXX"错误
- 关于crosses initialization of “XXX的问题
- crosses initialization of “XXX”
- crosses initialization of “XXX”
- gcc error: crosses initialization of XXX
- 两次碰到编译错误: crosses initialization of...
- error: jump to case label error: crosses initialization of xxx
- error:crosses initialization of ...的解决办法
- error:crosses initialization of ...的解决办法
- error: crosses initialization of
- crosses initialization of
- 解决问题crosses initialization of char
- error: jump to case label \n error: crosses initialization of xxx
- switch 语句:error : crosses initialization of 'xxx' and jump to case label [-fpermissive]
- C++ goto 在g++ 编译时出现 crosses initialization 和 jump to label xxx [-fpermissive] 错误
- gcc/g++ error: crosses initialization of
- error: jump to case label与crosses initialization of"xx"编译错误
- error: jump to case label 或者 error: crosses initialization of 编译错误
- vs2003安装出现重启计算机问题 和sql 安装问题
- 开博了
- MYSQL查询技巧
- oracle imp / exp 导入导出命令详解
- 功能强大界面漂亮的js日期控件 My97 DatePicker Ver 2.1
- 关于Symbian的"crosses initialization of XXX"错误
- 软件测试时代发展5周年的一个总结
- 钩子技术、HOOK技术应用(一)
- asp.net2.0中Membership的扩展
- ABAP:把内表中的内容导出为excel文件
- 代码怎样引用plug-in.xml, menifest.mf等配置文件的信息
- 开放的MODBUS TCP(一)
- csdn 老是发布失败
- 取款机中出现假币的分析