-1

I try to use strcmp. In Win32 C project all work, byt when I try compile this code in Eclipse Mars Atmel Avr Toolchain, then fail compile.

compile error in use of strcmp:

dereferencing pointer to incomplete type

struct Command{
    char* address;
    char* cmd; 
 };

 struct Command* parsedCommand = ParseCommand(PCmd); //PCmd - char* 
 if(parsedCommand != NULL)
 {
     if(strcmp(ADRES, *parsedCommand ->address) == 0)
Christian Gibbons
  • 4,272
  • 1
  • 16
  • 29
lgabryel
  • 109
  • 1
  • 9

3 Answers3

1

The issue is that you are both dereferencing parsedCommand and using the arrow notation to access the address.

Change

*parsedCommand ->address

to either

parsedCommand->address

or

(*parsedCommand).address
Tyler Marshall
  • 489
  • 3
  • 9
  • This not work. I use Atmel Avr Toolchain to compile hec for atmega microprocessors. – lgabryel May 01 '19 at 18:32
  • @lgabryel I do not understand your objection to this answer. What about it does not work as a result using the Atmel Avr Toolchain? – Christian Gibbons May 01 '19 at 18:36
  • I change code as you advise and I have this same compile error. – lgabryel May 01 '19 at 18:37
  • Does the compiler give you a line number? There's nothing wrong with `strcmp`. The compiler is complaining about use of the struct. Not sure why it could complain about the dereference because you declared it with `struct Command` – Tyler Marshall May 01 '19 at 18:44
  • Compile give line of `if(strcmp(ADRES, *parsedCommand ->address) == 0)` – lgabryel May 01 '19 at 18:55
1

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.

0

I was not including the definition of the Command strucutre. When I include the definition of the structure, all is fine.

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
lgabryel
  • 109
  • 1
  • 9