Re: [C] 2-dimensional arrays and functions

From: Jumbo ((nospam)_at_12freeukisp.co.uk)
Date: 10/31/03


Date: Fri, 31 Oct 2003 02:27:10 -0000


"Irrwahn Grausewitz" <irrwahn33@freenet.de> wrote in message
news:mr83qvc50bondfdhtrdhauh7a0md4mbq9r@4ax.com...
> "ellie fant" <pcrcutitout1000011@uko2.co.uk> wrote:
> > "Mike Wahler" <mkwahler@mkwahler.net> wrote:
> > > "John Smith" <JSmith@mail.com> wrote:
> > > > OK, that makes sense, but how do I prototype a function returning a
> > > > pointer to a 2D array? Can you show me a simple example?
> <snip>
> > > int (*func(void))[DIM1][DIM2]
> <snip>
> > What is the point in a function pointer that creates a static array?
> <sigh>
> There is no function pointer. You already now how to read declarators,
> don't you? Consider:
>
> func() func is a function
> func(void) taking no arguments
> (*func(void)) returning a pointer
> (*func(void))[][] to a 2D array
> int (*func(void))[][] of ints.
>
> > What you did could just as easily be done without the function:
> <snip>
> <sigh>
> The OP wanted to know how to prototype a function returning a pointer to
> a 2D array.
>
> > That function pointer just complicated things ?
> <sigh>
> There is no function pointer.
>
> > No?
> No.
> --
> Irrwahn
> (irrwahn33@freenet.de)

I'm glad you explained that to me because its been doing my head in since I
first seen it.
That seems very difficult to read to me.

but the reason I thought it was a function pointer was because of this
statement in main:
Sorry my mistake.
int (*p)[DIM1][DIM2] = func();

It an awfully confusing way of doing this:
static int array[DIM1][DIM2] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
12,13, 14, 15, 16};
It seems very difficult code to read but doesn't actually achieve anything
other than a simple static array declaration.

But it was the strange way the array brackets come at the end I found
interesting.
(*func(void))[][]
You would think it would be something like:
*[][] function void();

it's a difficult syntax to remember
 it seems unnatural to declare the return value after the parameter
brackets.
Can you explain this any further?