How do I define function returning pointer to function returning int?

Arthur B. Smith art at dinorah.wustl.edu
Thu Mar 8 07:26:39 AEST 1990


HELP!!

    My "ANSI C" references (K&R2 and Mark Williams' "ANSI C, A Lexical
Guide") are conflicting and vague on an important (to me) issue, and I
don't have a copy of the standard (draft or otherwise).  I think the 
pertinent section of the standard may be 3.7.1

    The simplest question is "Can you define a function of no
arguments that returns a pointer to a function returning int?"

    The next question is "How?"

    Several contenders I see are:

#1)
int (* gorp ()) ( void )
    {...}

#2)
int ((* gorp)()) ( void )
    {...}

#3)
typedef int (* gorp_t)();
gorp_t gorp ( int a, int b )
    {...}

#4)
typedef int ((* gorp_t)());
gorp_t gorp ( int a, int b )
    {...}

    Which of these are legal?  Why are those that are not legal
illegal?  Which of these can I reasonably expect a compiler to
support?  What about "old style" C?

    BTW, I am assuming that it is perfectly legal to pass parameters
that are pointers to functions returning int, e.g.,

int frzp ( int (* farg)() )
    {...}

or

int frzp2 ( int ((* farg)()) )
    {...}

if I am wrong here, please let me know!  (And again, what about "old
style" C?)

	I am
    	-art smith
(art at dinorah.wustl.edu    or   ...!uunet!wucs1!dinorah!art)



More information about the Comp.lang.c mailing list