typedefs and prototypes

Chris Torek chris at mimsy.UUCP
Sat Sep 24 01:23:20 AEST 1988


In article <12326 at oberon.USC.EDU> english at panarea.usc.edu (Joe English) writes:
>I found out by accident that such a construct does work in Borland's
>Turbo C (tm): ...

>typedef int func_t(int i, int j);
>
>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.'

True.  The dpANS says that the definition above (but, I think, NOT
the typedef declaration; for this I would have to check) is illegal.

>I just tried this construct on gcc, and it (quite rightly)
>doesn't work at all.

Incidentally, this has always bothered me about standard Pascal:

	type msgtype = array [1..80] of char; { or whatnot }
	procedure foo(i, j: integer; var msg: msgtype); forward;

	... many pages of code ...

	procedure foo;
	begin
	    { do stuff with i, j, and msg }
	end;
	...

One has to wonder where `i', `j', and `msg' came from:  Information
that is by rights purely local appears in a nonlocal place.

>Question: is giving parameter names in a
>function declaration (void foo(int i,int j);) part of the standard?

Yes.  The names themselves, however, are to be ignored by the compiler
(Turbo C is obviously not doing this).  (Whether this means that

	void foo(int i, char *i);

is legal I do not know.)
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain:	chris at mimsy.umd.edu	Path:	uunet!mimsy!chris



More information about the Comp.lang.c mailing list