I lack the requisite reputation to comment, so I'll temporarily post this as an answer and then delete/edit as appropriate. I suspect that your brief code listing leaves out some information about where the structure is declared and where the problematic code resides. Are they in the same file, or different files? Which files include which other files? Why do I want to know? Because the following code will give you a similar compilation error:
parsecmd.c:
#include <stdlib.h>
struct command {
char *addr;
char *cmd;
};
struct command *
parse_command(char *str)
{
struct command *ret = malloc(sizeof *ret);
if (ret == 0) return 0;
ret->addr = ....
ret->cmd = ....
return ret;
}
main.c:
#include <string.h>
struct command *parse_command(char *str);
int
main(void)
{
...
struct command *cmd = parse_command(pcmd);
if (cmd != 0) {
if (strcmp(address, cmd->addr) == 0) ...
}
}
When compiling main.c
, the compiler isn't aware of any complete declaration of the structure, which is why it is called an incomplete type. It also has no idea about what fields the structure has (or even its size), so it doesn't know what to make of the expression cmd->addr
.
Does this apply to you, or have I completely missed the mark here? If so, moving the complete struct declaration into a header file which is included both in all source files that use the structure should fix the problem.