More fun with types...

Kevin Martin kpmartin at watmath.UUCP
Fri Jan 18 14:05:46 AEST 1985


All the following assumes the existance of the formal parameter
declarations as described in the proposed draft standard.

The basic observation is that the formal parameter information is actually
part of the function's type, rather than a separate characteristic
of the function itself. That is, if I say

	extern int fun( char *, int );

'fun' is not a function returning int, and a function accepting
arguments of type char * and int, but is actually a function of
type "function accepting a char * and an int returning int".
Similarly, I can type things like

	typedef int (*funny)( char *, int );

which is a pointer to function accepting a char * and an int returning
an int. An object of type 'funny' could be used to point to 'fun'.

Question:
Given the above, and:

	extern int herbie( int, double );

should I be allowed to assign a pointer to 'herbie' to an object of
type 'funny'? In other words, should pointer-to-function types be
considered assignment-compatible ONLY if both the return type and
the formal parameter declarations match?

Related questions:
	What about functions for which no formal parameter declaration has
been supplied?
	How about making such types assignment-compatible as long as
the return type is the same, and all the arguments match in a somewhat
looser sense, i.e. int matches unsigned, char * matches unsigned char *,
as well as  other such type pairs which are "usually assumed" to be identical?
	The current situation is that function pointer types are assignment-
compatible as long as the return types are the same.
	If the strict interpretation is taken, the number of distinct
pointers to functions will become quite large even for a small set
of return types, and it is back to the old question:
What do we use for a generic function pointer?

                  Kevin Martin, UofW Software Development Group



More information about the Comp.lang.c mailing list