Declaring objects of type `function' ??

Ronald Guilmette rfg at ics.uci.edu
Wed Feb 21 20:00:41 AEST 1990


In article <25E18E05.16004 at paris.ics.uci.edu> rfg at 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 at ics.uci.edu)
// C++ Entomologist
// Motto:  If it sticks, force it.  If it breaks, it needed replacing anyway.



More information about the Comp.std.c mailing list