This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Compiler/AM3359: Type #395 pointer to incomplete class type is not allowed/incomplete type is not allowed

Part Number: AM3359

Tool/software: TI C/C++ Compiler

Compiler: TI v5.2.5

Payload_Manager.c:

struct __attribute__((__packed__))ATEIS_Payload	//payload
{
	u32 Addr;
	u16 Cmd;
	u16 Len;
	u8 Data[];	// If the expression is a constant expression, it shall have a value greater than zero. 所以裡面不能填0
};

Payload_Manager.h:

typedef struct ATEIS_Payload ATEIS_Payload_s;

DNM_PktXcvr.c:

#include "Payload_Manager.h"
ATEIS_Payload_s* pl_p = Payload_Manager_New(PAYLOAD_SIZE+dataLen); //incomplete type is not allowed

DNM_CmdHndlr.c:

#include "Payload_Manager.h"

ATEIS_Payload_s* pl_p = NULL;    //no problem

pl_p = OSTaskQPend(0, OS_OPT_PEND_BLOCKING, &msgSize, &ts, &err);	//wait for a message


DNM_temp = DNMManager_Ctor(DNM_temp,
                           &pl_p->Data[NAME],            //pointer to incomplete class type is not allowed
			   pl_p->Addr,                   //ditto
			   *(u32*)&pl_p->Data[SN],       //ditto
  			   *(u32*)&pl_p->Data[SUBMASK]); //ditto

I deliberately hide struct member in source file and only give enough information via header file.

I don't know why this doesn't work.

Thanks

  • Source lines that only work with pointers to ATEIS_Payload_s (declare pointers, pass pointers, assign pointers, etc.) are legal C even if all that is visible is this line from Payload_Manager.h ...

    Andy Lin94 said:
    typedef struct ATEIS_Payload ATEIS_Payload_s;

    All other source lines need to see the full definition of struct ATEIS_Payload that presently hidden away in Payload_Manager.c.  Consider ...

    Andy Lin94 said:
    ATEIS_Payload_s* pl_p = Payload_Manager_New(PAYLOAD_SIZE+dataLen);

    I presume PAYLOAD_SIZE is something like ...

    #define PAYLOAD_SIZE sizeof(ATEIS_Payload_s)

    That sizeof can only work if it knows all the members in the structure.  

    This line fails to compile ...

    Andy Lin94 said:
    &pl_p->Data[NAME]

    ... because the compiler does not know what members are in ATEIS_Payload_s.

    I think you are trying to implement abstract data types (you might call them opaque) as described in this FAQ (not from TI).

    Thanks and regards,

    -George

  • I presume PAYLOAD_SIZE is something like ...

    #define PAYLOAD_SIZE sizeof(ATEIS_Payload_s)

    No, it's:

    #define PAYLOAD_SIZE 8

  • I am unable to reproduce this behavior ...

    Andy Lin94 said:
    #include "Payload_Manager.h"
    ATEIS_Payload_s* pl_p = Payload_Manager_New(PAYLOAD_SIZE+dataLen); //incomplete type is not allowed

    For the source file DNM_PktXcvr.c, please follow the directions in the article How to Submit a Compiler Test Case.

    Thanks and regards,

    -George

  • I just did a little test to confirm that if without forward declaration, compiler knows identifier or not.
    The answer is no.

    I better read your FAQ and do more research about ADT. Thanks.