Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C typedef: parameter has incomplete type

Tags:

c

gcc

GCC 3.4.5 (MinGW version) produces a warning: parameter has incomplete type for line 2 of the following C code:

struct s;
typedef void (* func_t)(struct s _this);
struct s { func_t method; int dummy_member; };

Is there a way to fix this (or at least hide the warning) without changing the method argument's signature to (struct s *)?

Note:
As to why something like this would be useful: I'm currently tinkering with an object-oriented framework; 'method' is an entry in a dispatch table and because of the particular design of the framework, it makes sense to pass '_this' by value and not by reference (as it is usually done)...

like image 838
Christoph Avatar asked Feb 13 '26 09:02

Christoph


2 Answers

You can't quite do this easily - according to the C99 standard, Section 6.7.5.3, paragraph 4:

After adjustment, the parameters in a parameter type list in a function declarator that is part of a definition of that function shall not have incomplete type.

Your options are, therefore, to have the function take a pointer to the structure, or to take a pointer to a function of a slightly different type, such as a function taking unspecified parameters:

typedef void (* func_t)(struct s*);  // Pointer to struct
typedef void (* func_t)(void *);     // Eww - this is inferior to above option in every way
typedef void (* func_t)();           // Unspecified parameters
like image 50
Adam Rosenfield Avatar answered Feb 15 '26 00:02

Adam Rosenfield


Switching to GCC 4 seems like it should work. MinGW version 4.3.0: http://sourceforge.net/project/showfiles.php?group_id=2435&package_id=241304&release_id=596917

like image 36
Sean Avatar answered Feb 14 '26 22:02

Sean