Function returning pointer to function ? (80 lines)

Chris Torek chris at umcp-cs.UUCP
Sat Jul 20 12:02:43 AEST 1985


Once again, ``cdecl'' to the rescue:

> /* Now my turn to ask a question.  Here are the declarations: */
> char *f1()  { return("1"); }
> char *f2()  { return("2"); }
> /* decl array of ptrs to fns returning ptr to char */
> char *(*funcs[2])() = {f1,f2};
> /* decl ptr to array of ptrs to fns returning ptr to char */
> char *(*(*pfuncs)[])() = funcs; 
> /* "junk.c", line 47: warning: illegal pointer combination        */
> /* I can't get that to compile without a warning but it works ok. */

% cdecl << eof
declare pfuncs as pointer to array of pointer to function returning pointer to char
eof
Warning: Unsupported in C -- Pointer to array of unspecified dimension
char *(*(*pfuncs)[])()
%

It not only gives you the required declaration, it even tells you why
the compiler won't like it!  :-)
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 4251)
UUCP:	seismo!umcp-cs!chris
CSNet:	chris at umcp-cs		ARPA:	chris at maryland



More information about the Comp.lang.c mailing list