我们的代码涉及一个POD(Plain Old Datastructure)结构(它是一个基本的c ++结构,其中包含其他结构和POD变量,需要在开始时进行初始化.)
根据我所读到的,似乎:
myStruct = (MyStruct*)calloc(1, sizeof(MyStruct));
Run Code Online (Sandbox Code Playgroud)
应该将所有值初始化为零,如下所示:
myStruct = new MyStruct();
Run Code Online (Sandbox Code Playgroud)
但是,当以第二种方式初始化结构时,Valgrind后来抱怨"当使用这些变量时,条件跳转或移动取决于未初始化的值".我的理解是否存在缺陷,或者Valgrind是否会误报?
我正在研究一个Sudoku谜题生成器,并在调用JPanel的RemoveAll()方法之后/期间遇到一些间歇性的swing异常.当我在eclipse的调试模式下运行时,不会出现异常.以下是相关类的代码:
import java.awt.FlowLayout;
import java.awt.GridLayout;
import javax.swing.JLabel;
import javax.swing.JPanel;
/**
* Represents a cell in the GUI Grid display
* @author alex
*
*/
public class CellGUI extends JPanel {
public CellGUI()
{
super();
this.setLayout(new GridLayout(3,3));
for(int i = 1;i <=9;i++)
{
add(new JLabel("" + i));
}
setVisible(true);
}
public void clear()
{
this.removeAll();
this.validate();
this.setLayout(new GridLayout(3,3));
for(int i = 1;i <= 9; i++)
{
add(new JLabel("" + i));
}
}
public void setValue(int newVal)
{
if (newVal == 0) …Run Code Online (Sandbox Code Playgroud)