我在開關和結構方面存在小問題。C:在開關中需要整數表達式而不是XY
我有一個枚舉的所有說明。此Recond(活化)在INSTR結構(與節點adress-作爲三ADRESS代碼3個指針)蓄能
typedef enum {
// BUILT-IN FUNCTIONS
insIfj16readInt,
insIfj16readDouble,
insIfj16readString,
insIfj16lenght,
insIfj16substr,
insIfj16compare,
insIfj16find,
insIfj16sort,
insIfj16print,
//
// MATH
insPlus,
insMinus,
insMux,
insDiv,
//
//COMPARE
insEqual,
insNotEqual,
insLess,
insLessOrEqual,
insGreater,
insGreaterOrEqual,
insAssignment,
insFunctionCall
}InstrType;
typedef struct Instr {
BTSNode *Id1;
BTSNode *Id2;
BTSNode *Id3;
InstrType *type;
}Instr;
但現在,編譯器開始抱怨開關值。
開關碼是這樣的:
instrStack *instrStack;
// Pointer on instruction
struct Instr *instruction;
// Taking the first instruction from the instruction stack
instruction = instrStackTop(instrStack);
while(instruction != NULL) {
instruction = instrStackTop(instrStack);
switch (instruction->type) {
// BUILT-IN FUNCTIONS
case insIfj16readInt:
if(instruction->Id3->inc == 1) {
if (instruction->Id3->data.type == var_int) {
instruction->Id3->data.value.intValue = readInt();
} else {
throwException(4,0,0);
}
} else {
throwException(8, 0, 0);
}
break;
case insIfj16readString:
etc. etc. more code and so one.
因此,這裏的編譯器抱怨:
需要「整數表達在開關代替 'InstrType *'
我真的不知道爲什麼會發生這種情況,我在我的詞法分析器上用switch和enum使用了相同的「系統」(I ju改變自動裝置的狀態)並且這沒有問題。
就像編譯器說的那樣,'instruction-> type' - >'* instruction-> type'。投票結束這個簡單的錯字。 – Lundin