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:
* 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?Breaking up the declaration: GetMember is a function:
GetMember()
That takes one parameter of type CONTAINER_STRUCT *:
GetMember(CONTAINER_STRUCT *)
And returns a pointer:
*GetMember(CONTAINER_STRUCT *)
To a 3D array:
(*GetMember(CONTAINER_STRUCT *))[DIM_1][DIM_2][DIM_3]
Of struct MemberStruct:
struct MemberStruct (*GetMember(CONTAINER_STRUCT *))[DIM_1][DIM_2][DIM_3]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With