🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #5741

Problem with prototypes and incomplete types

#5741
From: M.T.Russell
Date: Sun, 26 Feb 1989 12:39
37 lines
1397 bytes
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@ukc.ac.uk
Technical Details
Message-ID: <237@harrier.ukc.ac.uk>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!decwrl!sun!pitstop!sundc!seismo!uunet!mcvax!ukc!harrier.ukc.ac.uk!mtr

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!decwrl!sun!pitstop!sundc!seismo!uunet!mcvax!ukc!harrier.ukc.ac.uk!mtr
From: mtr@ukc.ac.uk (M.T.Russell)
Newsgroups: comp.std.c
Subject: Problem with prototypes and incomplete types
Message-ID: <237@harrier.ukc.ac.uk>
Date: 26 Feb 89 12:39:28 GMT
Reply-To: mtr@ukc.ac.uk (M.T.Russell)
Organization: Computing Lab, University of Kent at Canterbury, UK.
Lines: 37