2024-07-03 02:10 AM - edited 2024-07-04 02:21 PM
Hello
Global definition of pointers:
unsigned int *uIntUtilityTmpP;
unsigned int *uIntP_2_UtilityTmp;
In a function I would like to initialize them with absolute values:
*uIntP_2_UtilityTmp=0x15;
*uIntUtilityTmpP=455;
uCharUtilityTmp=62;
sprintf(print_string,"1 -> *uIntP_2_UtilityTmp: 0x%x, *uIntUtilityTmpP: %d, uCharUtilityTmp: %d\n", *uIntP_2_UtilityTmp, *uIntUtilityTmpP, uCharUtilityTmp);
writeMessageRS232(PRIMARY_COM_PORT, (uint8_t *)print_string, strlen(print_string));
The printout on COM port shows following:
1 -> *uIntP_2_UtilityTmp: 0x1c7, *uIntUtilityTmpP: 455, uCharUtilityTmp: 62
Problem which I have here is that both pointer have the same value. When I write to *uIntP_2_UtilityTmp=0x15 I can see in debugger that also *uIntUtilityTmpP was refreshed with the same value. The same is the case in the next step when I write *uIntUtilityTmpP=455; and then variable *uIntP_2_UtilityTmp gets the same value in this case 455 which is 0x1c7.
Why this is so? What to set in compiler or in microcontroler that this works properly? I am using
STM32CubeIDE, Version: 1.13.0, Build: 17399_20230707_0829 (UTC)
Solved! Go to Solution.
2024-07-03 07:02 AM - edited 2024-07-04 02:17 PM
Ok, problem solved.
Both pointers have to be referenced to something. In this case to another unsigned int like this:
uIntUtilityTmp=455:
uIntUtilityTmpP=&uIntUtilityTmp; //reference the pointer to variable
Readout in debugger:
*uIntUtilityTmpP equals to 455
2024-07-03 07:02 AM - edited 2024-07-04 02:17 PM
Ok, problem solved.
Both pointers have to be referenced to something. In this case to another unsigned int like this:
uIntUtilityTmp=455:
uIntUtilityTmpP=&uIntUtilityTmp; //reference the pointer to variable
Readout in debugger:
*uIntUtilityTmpP equals to 455
2024-07-04 02:16 AM
@SMali.3 wrote:Ok, problem solved.
Good to know - please mark the solution.
Please note the </> button for posting code - see:
2024-07-04 12:08 PM
Thank you very much. I will do that next time.
2024-07-04 01:15 PM
Please mark the solution now.
2024-07-04 02:22 PM
Done!
2024-07-04 03:10 PM - edited 2024-07-04 03:15 PM
It's not showing ...
It should get a tick and green background - like this: