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)...
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With