【问题标题】:Compiler complain about “opcode_table undeclared (first use in this function)", why?编译器报错“opcode_table undeclared (first use in this function)”,为什么?
【发布时间】:2016-01-23 10:10:57
【问题描述】:

我有这个功能:

void run(int PC)
{
    int A = 0, op = 0, arg = 0, i = 0;
    char *xpress = NULL, *acode = NULL, strarg[CL_ARG_SIZE];
    while (1)
      {
        printf("PC: %03x | A: %03i |", PC, A);
        op = data[PC]; arg = data[PC+1];
        PC += 2;
        for (i=0 ; i<21 ; ++i)
             if (op == opcode_table[i].op)
             {
                 acode = opcode_table[i].mnemo;
                 sprintf(strarg, "0x%x", arg);   
                 xpress = replace(opcode_table[i].instruct, "_", strarg);
                 break;
              }
         printf(" %s %x\t| %s \t", acode, arg, xpress);
         step();
         exec_instruct(op, arg, &A, &PC);
    }
}

当我尝试编译我的程序时,出现以下错误:

:103:35: error:‘opcode_table’ undeclared (第一次在这个函数中使用) :103:35: 注意:每个未声明的标识符对于它出现的每个函数只报告一次

我做错了什么?

【问题讨论】:

    标签: c


    【解决方案1】:

    在您的函数中有三行代码,您可以在其中使用数组变量opcode_table 而无需先声明它。开始于:

    if (op == opcode_table[i].op)
    

    【讨论】:

    • @Yoan15 - 你需要了解这个程序在做什么,以及如何做。
    • 我了解程序在做什么,但我在声明变量 opcode_table 时遇到问题
    • 有人可以帮我解决这个问题吗?
    • 正如所写,您的问题无法回答。我建议你再发一篇,包括 MCVE 和具体问题。
    • 我的具体问题是这个函数中变量 opcode_table 的声明。我该如何声明:(op == opcode_table[i].op)?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-08-06
    • 1970-01-01
    • 2021-01-17
    • 1970-01-01
    • 2013-03-24
    • 2017-06-01
    • 1970-01-01
    相关资源
    最近更新 更多