I came across this odd function declaration in my code base that I would like help understanding:
struct MemberStruct (*GetMember (
CONTAINER_STRUCT *Buffer
))[DIM_1][DIM_2][DIM_3]
{
return(&Buffer->MemberStructArray);
}
It behaves like a pseudo-accessor. It returns the address of the MemberStruct array within CONTAINER_STRUCT.
CONTAINER_STRUCT has this definition:
typedef struct ContainerStruct {
// Other members
struct MemberStruct MemberStructArray[DIM_1][DIM_2][DIM_3];
// Other members
} CONTAINER_STRUCT;
This function is called like this:
// declarations at the top of a function
struct MemberStruct (*MemberStructArray)[DIM_1][DIM_2][DIM_3];
CONTAINER_STRUCT Container;
// Other code, including the initialization of Container
MemberStructArray = GetMember(&Container);
I'd like to better understand the function signature, and haven't been able to find any examples of this construct online. My specific questions are:
- How do the array dimensions after the name of the function work? How do they relate to the return type when the function name is between the return type and the dimensions?
- Why is the
*symbol inside the parenthesis with the function name? Since this is returning an address, shouldn't the reference operator be bound to the return type rather than the function name?