We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
I have a problem when I try to get a function to update a the address of a pointer. Code:
const unsigned char array1[10] = {1, 2, 3, 4....} void func1 (const unsigned char *ptr) { ptr = array1; } void func2 (void) { const unsigned char *ptr1; func1 (ptr1); if (ptr1[0] == 1) { ..... } }
The problem is, the ptr in func1 gets the right address, but when I return to func2, ptr1 doesn't get updated. I have tried to remove the const from the variable definition in func2 without any succes.
array1 must be defined as a const because in the real code it's a lot bigger.
I have tried to set ptr1 directly in func2.
... void func 2 (void) { const unsigned char *ptr1; ptr1 = array1; if (ptr1[0] == 1) { ..... } }
This work fine. But this is not an option in my application.
uC: STR712 compiler: CARM
"Actually this is textbook C stuff. You might want to consult your favorite C book once more."
You need to review how 'C' passes parameters to functions - it passes by value only...