使用未申报的标识符

use of undeclared identifier

本文关键字:标识符      更新时间:2023-10-16
static void cmd_help(char *dummy)    
{
    struct command *c;
    puts("commands are:");
    c = mscp_commands;
    do {
          printf("%-8s - %sn", c->name ? c->name : "", c->help);
    } while (c++->name != NULL);
}
struct command mscp_commands[] = {
    ....
};

我正在尝试将程序从C转换为C 。资格是它通过G 编译;

我遇到了这个错误:

错误:使用未确定的标识符'MSCP_Commands' c = mscp_commands;

我认为它必须对无法"看到" struct命令的函数做一些事情。有人可以帮忙吗?

在C 中,所有内容都应在使用前声明或定义。当编译器找到以前从未见过的标识符,就像c = mscp_commands;中的mscp_commands一样,它会发出错误。您需要将mscp_commands的定义移动或至少像

一样声明
extern struct command mscp_commands[];

使用此标识符。

这些语言的概念是"正向声明"。这样的声明说,名称Blah是结构或枚举,而无需提供任何其他细节。但至少应该存在。否则,这是语法错误。在您的示例中,command没有任何内容。

移动

struct command mscp_commands[] = {
};

cmd_help函数之前。