UNION-type-punning error in IAR CSTAT Analyse

Viewed 75

I have a this type structure in example.h file like this:

typedef union{
uint16_t valNum;
struct{
uint8_t valNumH;
uint8_t valNumL;
};
} valueExp;

And I am using this structure in example.c file:

uint16_t myFunction(uint16_t tempData){
uint8_t myData[8];
ValueExp mainValue;
mainValue.valNum=tempData;
myData[5]=mainValue.valNumH;

}

When I analyse IAR-CSTAT analyse this function I get this error:

Union mainValue is written as valNum then read as another field - UNION-type punning

How can I solve this message ?

0 Answers
Related