On Thu, Nov 3, 2011 at 1:43 AM, Tomek CEDRO <tomek.ce...@gmail.com> wrote:
> Hello Andreas :-) > > On Thu, Nov 3, 2011 at 12:36 AM, Andreas Fritiofson > <andreas.fritiof...@gmail.com> wrote: > > This won't even compile. You pass a pointer-to-int, but swd_bus_read_ack > > expects a pointer-to-pointer-to-char. > > naah this is only typo in mind-shortcut, code builds well, but i dont > get it why i cannot use single pointer to pass back a memory location > to function caller... this is what pointers exist.. > > Ah, well, but c passes parameters by value, to get out parameters you have to go via a pointer. Consider: void foo(int x) { x++; } int main(void) { int a = 3; foo(a); return 0; } Did you expect the value of a to change after the call to foo? No, didn't think so. You'd have to do this instead: void foo(int *x) { *x++; } int main(void) { int a = 3; foo(&a); return 0; } Here a gets the value 4 after the call to foo. Now change the variable type to a pointer instead of an integer: void foo(int **x) { *x++; } int main(void) { int *a = &bar; foo(&a); return 0; } Here a points to the integer following bar after the call to foo. It's exactly the same concept, just a change of variable type from int to int*. Note that &a is now a double pointer, nothing magic here. Do the same variable type change in the first, non-functional, example and convince yourself that that wont work either.
_______________________________________________ Openocd-development mailing list Openocd-development@lists.berlios.de https://lists.berlios.de/mailman/listinfo/openocd-development