Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.1 6/24/83; site mgweed.UUCP
Path: utzoo!watmath!clyde!burl!ulysses!mhuxr!mhuxt!mhuxj!houxm!ihnp4!mgnetp!mgweed!plw
From: plw@mgweed.UUCP (Pete Wilson)
Newsgroups: net.lang.c
Subject: Re: declaring routines which return function pointers
Message-ID: <14240@mgweed.UUCP>
Date: Sun, 16-Dec-84 23:37:37 EST
Article-I.D.: mgweed.14240
Posted: Sun Dec 16 23:37:37 1984
Date-Received: Tue, 18-Dec-84 02:44:54 EST
References: <249@alberta.UUCP>
Distribution: net
Organization: AT&T Consumer Products - Montgomery Illinois
Lines: 55


	In the following truly useless code, lint(1) on Sys V only
complains about 'x' being set but not used. The code was derived from
reading the man section on signal(2):

	main()
	{
		int fa();
		int (*fr())();
		int (*x)();
	
		x = fr(fa);
	
	}
	int (*fr(fp))()
	int (*fp)();
	{
		int nfp();
	
		if ( fp )
			return(fp);
		return(nfp);
	}
	nfp()
	{
		return(0);
	}
	fa()
	{
		return(0);
	}

	Unfortunately, K&R is not too clear about functions which return
pointers to functions. Consistance in declarations and definitions is
what keeps lint happy. Notice the declaration of 'fr' in 'main'. It is
declared as a function which returns a pointer to a function. Later in
the file it is defined in the same way.
	Derivation:

	int f();	/* function which returns an int */
	int *f();	/* function which returns a pointer to an int */
	int (*f)();	/* holds a pointer to a function */
	int (*f())();	/* function which returns a pointer to a
			   function which returns an int */
	???		/* holds a pointer to a function which returns
			   a pointer to a function which returns an
			   int???   DON'T ASK!! */
	
	Still not very clear? I agree!! One can get lost in the depths
of parentheses!!

					Pete Wilson
					AT&T-CP Montgomery Works
					Montgomery, IL
					..ihnp4!mgweed!plw