Given: SInt16 *samples = NULL;
What does (char **)(&samples) declare?
Edit to show actual use case:
CMBlockBufferGetDataPointer(audioBlockBuffer, audioBlockBufferOffset, &lengthAtOffset, &totalLength, (char **)(&samples));
// CMBlockBufferGetDataPointer(<CMBlockBufferRef theBuffer>, <size_t offset>, <size_t *lengthAtOffset>, <size_t *totalLength>, <char **dataPointer>)
Update: The original question was asking simply
What does (char **)(&samples) declare?As such, in my original answer I tried to outline the possible uses of that syntax in the abstract. But subsequently it was clarified that this was for a parameter toCMBlockBufferGetDataPointer. But I’ll leave my original answer for the sake of completeness.Original answer:
This syntax has one of two possible interpretations. First, this syntax can be used as a pointer to a pointer of a
SInt16which has been cast to a pointer to a pointer of achar. By the way, Apple uses the term indirect reference for these pointers to pointers. Or, second, this could be a pointer to an array ofSInt16which has been cast to a pointer to an array ofchar. It depends upon how this(char **)&samplesis being used.Focusing on the first interpretation, in your example the variable
samplesis defined to be(SInt16 *), a pointer (or direct reference) to aSInt16(a signed short integer). Thus&samplesis the address of that thatsamplespointer, which could properly be used in any situation where you need to pass a pointer to a pointer (an indirect reference) of aSInt16, namely(SInt16 **).In terms of where you’d use a pointer to a pointer, an indirect reference, it’s frequently used when you have a method that will allocate some memory for some object and it needs to update one of your pointers with a reference to this new object. The most common Cocoa example of this construct is the frequent use of
(NSError **). You can see examples of this in Apple’s Error Handling Programming Guide.What’s strange about your example, is that you’re casting
&samples, your indirect reference to aSInt16(or a pointer to an array ofSInt16), to be a(char **), acharindirect reference (or an array ofchar). That sends a shudder down the spine of all of us reformed C programmers. If you do this, you should be very, very comfortable with the code that is using this construct as this is a little dangerous. But I realize that we’re sometimes constrained by legacy code.