Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!cs.utexas.edu!usc!brutus.cs.uiuc.edu!jarthur!uci-ics!rfg From: rfg@ics.uci.edu (Ronald Guilmette) Newsgroups: comp.std.c Subject: Re: Declaring objects of type `function' ?? Message-ID: <25E258B8.7142@paris.ics.uci.edu> Date: 21 Feb 90 09:00:41 GMT References: <25E18E05.16004@paris.ics.uci.edu> Reply-To: rfg@ics.uci.edu (Ronald Guilmette) Organization: UC Irvine Department of ICS Lines: 40 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.