问题描述
GCC 3.4.5(MinGW版本)会产生一个警告:对于以下C代码的第2行,参数有不完整的类型:
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; };
有没有办法解决这个问题(或至少隐藏警告)而不改变方法参数的签名to(struct s *)?
Is there a way to fix this (or at least hide the warning) without changing the method argument's signature to (struct s *)?
注意:至于为什么这样做会有用:我目前正在修改一个对象 - 面向框架; 'method'是一个调度表中的条目,并且由于框架的特殊设计,按值传递'_this'而不是引用(通常是这样做)是有意义的... ...
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)...
推荐答案
警告似乎是当前MinGW版本gcc的一个错误。与亚当所说的相反,它 是有效的C99 - 第6.7.5.3节,第12段明确允许:
The warning seems to be a bug with the current MinGW version of gcc. Contrary to what Adam said, it is valid C99 - section 6.7.5.3, paragraph 12 explicitly allows this:
似乎没有办法指示(此版本)gcc不打印此警告 - 至少 找不到交换机工作 - 所以我现在只是忽略它。
There seems to be no way to instruct (this version of) gcc to not print this warning - at least I could not find a switch which worked - so I'm just ignoring it for now.
这篇关于C typedef:参数的类型不完整的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!