Pointer structure with a parameter : pointer of tab


Joined
Dec 8, 2021
Messages
1
Reaction score
0
Hello,

I work with a XMC45 and I communicate with my PC by modbus. For that I create 2 structures :


typedef struct
{
uint32_t STATUS;
...
} Data_Modbus_Input_Register;


typedef struct
{
uint32_t HibernateCmdStatus;
chr8_t *strMsg;
...
} Data_Modbus_Holding_Register;


After I create pointer of these structures :
Input_Register = (Data_Modbus_Input_Register*)&reg_input_buffer;
Holding_Register = (Data_Modbus_Holding_Register*)&reg_holding_buffer;

At this moment all work, I can write/read with modbus.

My problem is : I would like to read a string, so i create a pointer of a tab in one of the structure "chr8_t *strMsg"
and I would like to affect it value like : "hello you"
So i write : Holding_Register->strMsg = "hello you"

But I receive "uoy".
I think it's my definition with is not good.
Someone can help me ?

Bests regards,
Pierre
 
Ad

Advertisements

Joined
Mar 3, 2021
Messages
243
Reaction score
29
That definition may or may not be right. It depends on how you're assigning the string and how it's being read. It's a pointer, so it can safely point to a global static string (one written to flash). But, you can't dynamically write to it as it was not allocated any actual memory space (either "chr8_t strMsg[16]" or "chr8_t *strMsg = new chr8_t[16]"). So, it depends on how, exactly you're writing and reading it. Can you post those?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top