Reputation: 143
static void cmd_help(char *dummy)
{
struct command *c;
puts("commands are:");
c = mscp_commands;
do {
printf("%-8s - %s\n", c->name ? c->name : "", c->help);
} while (c++->name != NULL);
}
struct command mscp_commands[] = {
....
};
I am trying to convert a program from C into C++. The qualification is that it compiles through g++;
I am getting this error:
error: use of undeclared identifier 'mscp_commands' c = mscp_commands;
I'm thinking that it has to do something with the function not being able to "see" the struct command. Can someone help please?
Upvotes: 0
Views: 4343
Reputation: 10557
In C and C++ everything should be declared or defined before use. When compiler finds an identifier that it has not ever seen before, like your mscp_commands
in c = mscp_commands;
it issues an error. You need to move definition of mscp_commands
up or at least declare it like
extern struct command mscp_commands[];
before using this identifier.
These languages have concept of "forward declaration". Such declarations say that name Blah
is structure or enum without giving any further details. But at least this should be present. Otherwise it is a syntax error. In your example there is nothing about command
.
Upvotes: 1
Reputation: 13532
Move
struct command mscp_commands[] = {
};
before the cmd_help
function.
Upvotes: 0