Function returning pointer to function

Andrew Koenig ark at alice.UUCP
Sun Jul 21 01:36:42 AEST 1985


> char cd[2] = {'c','d'};
> char (*pcd)[] = cd;
> /* "junk.c", line 55: warning: illegal pointer combination        */

> /* What is it that the compiler (4.1 BSD) doesn't like?          */

Well, let's see.  You are saying that pcd is a thing such that if
you dereference it and the subscript it, you get a char.  In other words,
pcd is a pointer to a pointer to a char.  cd is a pointer to char,
so you can't assign it to pcd.

Now, if you had said:

char cd[2] = {'c','d'};
char *pcd[] = {cd};

you are now saying that you can subscript pcd and then dereference
it to get a char.  Thus pcd is an array of pointers to chars; the
length of the array is given by the initialization to be 1.



More information about the Comp.lang.c mailing list