I have to add a piece of code to a big code that already exists. I have a pointer in my code, *Ptr. This pointer is of type, unsigned char.
unsigned char *Ptr;
And I have the below struct.
struct
{
uint8_t tag;
uint16_t data[size];
bool status;
}Test;
Test *TagData;
The pointer is typecasted as below and Now the struct pointer is pointing to the location pointed by the pointer Ptr;
TagData = (Test *)Ptr;
In my code, I will be copying some output values to this structure so that those values get copied to the memory location pointed by *Ptr.
In order to copy some values to the data array in the structure, I need to find the offset to that struct member. I want to do it without using offsetof function. I tried doing the below and I get compiler error.
TagData->data = (uint16_t *) (Ptr + sizeof(TagData->tag));
Can anyone tell how to do this ? And I don't want to use the offsetof function. Is there a simpler way to do this?