Search code examples
carraysstructassignment-operator

Why is there an error: incompatible types when assigning to type 'P_Name_t' from type 'UINT8 *'


I don't understand why I am getting the error above and how to fix it. Please help.

//STRUCTURES
typedef UINT8 P_Name_t[5];
typedef UINT8 ChipSN_t[3]; 

typedef struct                   
{  
   ChipSN_t  ChipSN; 
   <other members>   
} ChipIdent_t;


typedef struct Data_t              
{ 
   ChipIdent_t      ReadOnlyMemID;
    <other members>   
} Data_t;


typedef struct                
{
   P_Name_t NameOfPart;   
   <other members>
} Log_t;

Data_t     Data_Src;

typedef struct
{
   P_Name_t       NameOfPart;           
   ChipSN_t       ChipSN;   
}PartNum_ID_t;


//VARIABLE DECALARTION
PRIVATE PartNum_ID_t PN_ChipID[12]; 
PRIVATE Log_t   *LogEntry = NULL;               


//Usage in code
PN_ChipID[0].NameOfPart = LogEntry->NameOfPart; 
PN_ChipID[0].ChipSN = Data_Src.ReadOnlyMemID.ChipSN;

I don't understand why I get the error. The LogEntry->NameOfPart is of type P_Name_t and PN_ChipID[0].NameOfPart is of the same type. I don't know if I am missing something here. Please explain.


Solution

  • incompatible types when assigning to type 'P_Name_t' [...]
    

    [...] why i get the error[?] The LogEntry->NameOfPart is of type P_Name_t and PN_ChipID[0].NameOfPart is of the same type.

    P_Name_t is an array, namely of 5 unit8_t.

    PN_ChipID[0].NameOfPart is of type P_Name_t.

    So this line

    PN_ChipID[0].NameOfPart = LogEntry->NameOfPart;
    

    tries to assign to an array, namely to PN_ChipID[0].NameOfPart.

    In C it is not possible to assign to an array, hence the error during compilation of the above line.