MATLAB: Pointer in a C mex sfunction

c codehandle the pointerspointers-function

Hello,
I have some problems to understand the syntax and the meaning of some pointers used in a C sfunction For example taken the output method of the TimesTwo sfunction
From which I reported an extract hereafter
Int_T i;
InputRealPtrsType uPtrs = ssGetInputPortRealSignalPtrs(S,0);
real_T *y = ssGetOutputPortRealSignal(S,0);
int_T width = ssGetOutputPortWidth(S,0);
for (i=0; i<width; i++) {
/*
* This example does not implement complex signal handling.
* To find out see an example about how to handle complex signal in
* S-function, see sdotproduct.c for details.
*/
*y++ = 2.0 *(*uPtrs[i]);
}
}
what is it supposed to mean *y++ (is the value to which the y pointer refers, isn't? but I'm wondering why there is the ++ notation following *y, I thought it's to point to the next memory area because we deal with a static vector). Am I right?
And what does it means (*uPtrs[i])? I thought it was the value of the variable to which the pointer points to.
is there anyone, who can help me to figure it out? can you suggest me some good references to understand how this stuff works?
thanks for reading

Best Answer

You don't show the definitions of Int_T, real_T, and InputRealPtrsType, so I am guessing a bit here.
y is a pointer to a real_T type.
*y is the real_T value that is being pointed to by y. I.e., it is the value at the memory address contained in the y variable.
The expression " *y++ = right_hand_side " means assign the value of right_hand_side to the real_T value that y is currently pointing to in memory, and then increment y to point to the next real_T value in memory. The ++ is the increment operator and the * is the dereference operator.
If uPtrs is a pointer to a pointer (or an array of pointers) to a real_T type, then uPtrs[i] is the i'th pointer in that array, and *uPtrs[i] is the real_T value at the memory address that uPtrs[i] is currently pointing to. The square brackets [ ] (array element) have higher precedence than the * operator (dereference).
So the breakdown is this:
*y++ = 2.0 *(*uPtrs[i]);
" Take the real_T value that uPtrs[i] is currently pointing to, multiply that by 2, assign this result to the memory location that y is currently pointing to, and then increment y to point to the next real_T value in memory."
If u0 is an array of pointers to a real_T type, then u0[0] is the first pointer in that array, and *u[0] is the real_T value that u[0] is pointing to in memory.