2009-12-03 144 views
0

如果我得到的一个变量操作码可能尚未初始化函数出错,这应该这个方法中,或在课程开始时进行。变量初始化

private void compileDo() { 
     int endLabel, endLabelLoc, topLabel, opcode; 
     accept("do"); 
     accept("("); 
     compileExpr(); 
     accept(")"); 
     topLabel = cs.getPos(); 
     endLabelLoc = cs.emit(opcode, topLabel); 
     compileStatement(); 

    } 

任何帮助将不胜感激。

回答

1

是这样的:

int opcode = 0; 

码是一个局部变量,因此,你应该在函数中初始化。