Reputation: 77
I get this following error when I do this
"error: storage size of 'mscp_commands' isn't known"
struct command mscp_commands[]; /* forward declaration */
Later on I have:
struct command mscp_commands[] = {
{ "help", cmd_help, "show this list of commands" },
{ "bd", cmd_bd, "display board" },
{ "ls", cmd_list_moves, "list moves" },
{ "new", cmd_new, "new game" },
{ "go", cmd_go, "computer starts playing" },
{ "test", cmd_test, "search (depth)" },
{ "quit", cmd_quit, "leave chess program" },
{ "sd", cmd_set_depth, "set maximum search depth (plies)" },
{ "both", cmd_both, "computer plays both sides" },
};
What's wrong with forward declaring the struct mscp_commands that way?
The command struct is defined earlier:
struct command {
char *name;
void (*cmd)(char*);
char *help;
};
Upvotes: 0
Views: 4984
Reputation: 88711
struct command mscp_commands[];
is a definition not a declaration (assuming struct command
is defined), but it doesn't know the storage size at that point, because the number of elements in mscp_commands
isn't known. It's one of the cases where []
is notably different to *
.
You could however write:
extern struct command mscp_commands[];
which would indeed be a declaration.
Upvotes: 7