Suppose I have an API function which returns a pointer to some memory, that is later to be consumed in an array-like manner. Suppose also that its size is known in advance, and that it’s declared like so:
returntype API(void);
Is it better for the function’s return type to be declared as pointer to an array, like so:
typedef struct data (*returntype)[];
or for it to be defined as simply the good old pointer to the first element, like so:
typedef struct data *returntype;
On one hand returning a pointer to an entire array seems to make more sense, but on the other the API consumer would probably prefer the 2nd version because it’s easier to consume:
e.g. from the consumer’s perspective, copying the 3rd struct
in the array:
1st declaration:
returntype = API(); struct data third= (*returntype)[2];
2nd declaration:
returntype = API(); struct data third = returntype[2];