[comp.std.c] Declaring objects of type `function' ??

rfg@ics.uci.edu (Ronald Guilmette) (02/21/90)

In article <25E18E05.16004@paris.ics.uci.edu> rfg@paris.ics.uci.edu (Ronald Guilmette) writes:
>Here is another one of your run-of-the-mill "Is it legal" type questions.
>
>Is this legal?
>
>	typedef int (function) ();
>
>	function global_function_object;	/* dubious */
>
>	int global_function_object ()
>	{
>	  return 0;
>	}
>
>The GNU C compiler says yes.  A C compiler (presumably pcc2) on a 386
>systems says yes.  The Sequent Symmetry C compiler says yes.  The AT&T
>C++ (2.0) translator says yes.  The GNU g++ compiler says yes.  The
>Sun Sparcstation-1 compiler says no.
>
>Neither 3.5.4.3 nor 3.5.6 of the ANSI C standard seem to address the issue.

OK.  I guess that the question above was not sufficiently tantalizing to
provoke an immediate same-day response. :-)  How about if I liven it up a bit?

How about:

	function global_function_array[];	/* very dubious */

Now is that legal?

Believe it or not, AT&T's cfront 2.0 C++ to C translator accepts things like
this!  If you really want a surprize, it even accepts this:

	function global_function_array[1] = { global_function_object };

The semantics of this are entirely less than clear to me.

// Ron Guilmette (rfg@ics.uci.edu)
// C++ Entomologist
// Motto:  If it sticks, force it.  If it breaks, it needed replacing anyway.

henry@utzoo.uucp (Henry Spencer) (02/22/90)

In article <25E18E05.16004@paris.ics.uci.edu> rfg@paris.ics.uci.edu (Ronald Guilmette) writes:
>Is this legal?
>	typedef int (function) ();
>	function global_function_object;	/* dubious */
>	int global_function_object ()
>	{

Check out 3.7.1 and the footnote thereto.  You can't inherit the
function-ness from a typedef in a function *definition*, but it's
legal in a declaration.
-- 
"The N in NFS stands for Not, |     Henry Spencer at U of Toronto Zoology
or Need, or perhaps Nightmare"| uunet!attcan!utzoo!henry henry@zoo.toronto.edu