I read this question: what does the line int *(*(x[3])())[5]; do in C?
which have the code line:
int *(*(*x[3])())[5];
in this answer https://stackoverflow.com/a/37364752/4386427
According to http://cdecl.org/ this means
declare x as array 3 of pointer to function returning pointer to array 5 of pointer to int
Now I'm wondering about this part:
function returning pointer to array 5 of pointer to int
How does the proto-type for a function returning pointer to array 5 of pointer to int look?
I tried this:
int* g()[5] <---- ERROR: 'g' declared as function returning an array
{
int** t = NULL;
// t = malloc-stuff
return t;
}
which doesn't compile.
Then I tried
#include <stdio.h>
#include <stdlib.h>
int *(*(*x[3])())[5];
int** g()
{
int** t = NULL;
// t = malloc-stuff
return t;
}
int main(void) {
x[0] = g;
return 0;
}
which compiles fine but now the return type is more like pointer to pointer to int. There is nothing that says pointer to array 5 of pointer to int
So my question is:
Is it at all possible to write a function which returns pointer to array 5 of pointer to int ?
If yes, how does the proto-type look?
If no, what is the purpose of 5 in the declaration of x?
int *(*(*x[3])())[5];
^
what does 5 mean here?
int* (*g())[5]More parentheses are clearly the universal antidote, as more indirection is a panacea.x[1]=g2;even whenint* (*g())[2](i.e. 3 instead of 5). I don't get any warnings - at least not here: ideone.com/mVt8g9