Problem with prototypes and incomplete types

M.T.Russell mtr at ukc.ac.uk
Sun Feb 26 22:39:28 AEST 1989


Consider the following code fragment:

	typedef struct object {
		int id;
		void (*destroy)(struct object *);	/* line 3 */
	} object;

	void destroy(object *obj)
	{
		/* destroy the object */
	}

	void f(object *obj)
	{
		(*obj->destroy)(obj);			/* line 13 */
	}

When I compile this with gcc 1.32 (the only ANSI C compiler I have access to)
I get the following:

	obj.c:3: warning: parameter `obj' points to incomplete type
	obj.c: In function f:
	obj.c:13: incompatible types in argument passing

Is gcc right to object to incomplete types in function prototypes?
If so, is there any way to specify the type of a member of a structure
which is a pointer to a function taking a pointer to the structure
as an argument (sorry, I can't think of a better way to phrase this :-)).

One workaround is to declare destroy as

	void (*destroy)(void *);

but this loses type information.

Mark Russell
mtr at ukc.ac.uk



More information about the Comp.std.c mailing list