I made this minimal working example of a larger piece of code I have.
The problem is, that sizeof prints for the first call 16, which is the correct size, and for the 2nd call only 8. The wierd thing is, it always prints 8, independent of the size of the struct, whether there's only one value or 10 values in it.
struct test_struct
{
int32_t val1;
int32_t val2;
int32_t val3;
int32_t val4;
};
unsigned char * StructToChar(test_struct structy)
{
unsigned char returnval[sizeof(structy)];
memcpy(returnval, &structy, sizeof(structy));
return returnval;
}
int main()
{
test_struct sendstruct = {};
unsigned char *test_array = StructToChar(sendstruct);
unsigned char returnval[sizeof(sendstruct)];
memcpy(returnval, &sendstruct, sizeof(sendstruct));
printf("%d\n", sizeof(returnval));
printf("%d\n", sizeof(test_array));
return 0;
}