msg->data
is an array.
As such, it does not have an l-value, and you cannot change it.
That's why you're getting a compilation error for the first option mentioned above.
For the second and third options mentioned above, you're getting a memory access violation during runtime, probably because your msg
variable is not initialized to point to a valid memory address.
Assuming that you have data_t* msg
declared in the right place, you still need to initialize it:
data_t* msg = (data_t*)malloc(sizeof(data_t));
You should also make sure that you free(msg)
at a later point in the execution of your program.
BTW, you have not specified the entire structure of your program, but a simple data_t msg
instance might be sufficient for your needs (in which case, you don't need to use the malloc
and the free
).
And as mentioned in a comment by @Shahbaz, if you do end up using malloc
and free
, then you need to make sure that your platform (OS or BSP) supports dynamic memory allocation (AKA heap).