C typedef: parameter is an incomplete type

GCC 3.4.5 (MinGW version) generates a warning: the parameter is not a partial 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 signature of the method argument (struct s *)?

Note. . Something like this would be useful: I am now engaged in an object-oriented structure; "method" is an entry in the dispatch table, and due to the specific design of the frame, it makes sense to pass "_this" by value rather than by reference (as is usually done) ...

+3
source share
5 answers

The warning seems to be a bug with the current version of gcc MinGW. Contrary to what Adam said, indeed, C99 - section 6.7.5.3, paragraph 12 explicitly allows this:

If the function declarator is not part of the definition of this function, the parameters may be of an incomplete type and may use the notation [*] in their sequences of declarator qualifiers to indicate the types of arrays of variable length.

There seems to be no way to instruct (this version) gcc not to print this warning - at least I couldn't find the shift I was working with - so I'm just ignoring it now.

0
source

You cannot do this easily - according to C99 standard , section 6.7.5.3, paragraph 4:

After setting the parameters in the list of parameter types in the function declarator, which part of the definition of this function should not have an incomplete type.

Thus, your parameters must have a function by pointing to a structure pointer, or take a pointer to a function of a slightly different type, such as a function that accepts 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 
+1
source

Hiding warnings is usually quite simple - just look for help for your specific compiler.

http://developer.apple.com/documentation/DeveloperTools/gcc-4.0.1/gcc/index.html#//apple_ref/doc/uid/TP40001838

Please note that suppressing warnings is generally not what I would advocate.

0
source
0
source

You want to call it a function pointer. Why not use a void pointer instead?

 typedef void (*func_t)(void*); 

You MAY be able to pass a pointer to a function as well; I do not have a compiler.

 typedef void (*func_t)(void (*)()); 
-one
source

All Articles