Path: utzoo!attcan!uunet!ncrlnk!ncr-sd!hp-sdd!hplabs!sm.unisys.com!oberon!panarea.usc.edu!english From: english@panarea.usc.edu (Joe English) Newsgroups: comp.lang.c Subject: Re: typedefs and prototypes Message-ID: <12326@oberon.USC.EDU> Date: 23 Sep 88 02:18:06 GMT References: <7135@bloom-beacon.MIT.EDU> <8543@smoke.ARPA> <13664@mimsy.UUCP> Sender: news@oberon.USC.EDU Reply-To: english@panarea.usc.edu (Joe English) Organization: USC Committee for Pink and Gray Lines: 41 In article <13664@mimsy.UUCP> chris@mimsy.UUCP (Chris Torek) writes: >Note that you cannot use a typedef to define a function type: i.e., >`typedef func_arg_int_ret_int int(int);' is illegal. The problem is >that, given this definition, there is nowhere to put the parentheses >and the formal, so that transforming > > /* identity fn */ > int identity(int i) { return i; } > >to > > func_arg_int_ret_int identity { return i??? } > >leaves us nowhere to declare `i'. (If we needed no arguments, it >might work, but it makes the grammar inordinately difficult.) I found out by accident that such a construct does work in Borland's Turbo C (tm): I had a slew of functions that took the same parameters to go into an array, and I included a prototype in the typedef to enable type-checking when they were called indirectly. It turns out that if the typedef includes parameter names, like typedef int func_t(int i, int j); then function definitions will only work like this: func_t foo { return i+j; } !!! Of course, func_t foo(int a, int b) is a "function returning a function," so the omission of the parameters in the definition makes 'sense.' I just tried this construct on gcc, and it (quite rightly) doesn't work at all. Question: is giving parameter names in a function declaration (void foo(int i,int j);) part of the standard? The Turbo manual says to do this for clarity, but I will drop this practice if it is nonportable. /|/| Joe English -----< | | j.e. O \|\| ARPA: english%lipari@oberon.usc.edu