array type has incomplete typeelement type是什么意思怎么解决

GCC: array type has incomplete element type? - Stack Overflow
to customize your list.
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.
J it only takes a minute:
Join the Stack Overflow community to:
Ask programming questions
Answer and help your peers
Get recognized for your expertise
GCC gives me an "array type has incomplete element type"-error message when i try to compile this:
typedef struct _
struct _node{
node (*children)[2];
In memory the struct should look like this
0x pointer to 1. child node
0x pointer to 2. child node
That's because the C type expression works the other way round.
node (*children)[2];
reads as the following: the contents of children, when dereferenced (* is applied to them), yield something on which the array operator [] can be applied, yielding a node. Which means that children is a pointer to an array of two node. However, you do not want a pointer to an array, you want an array of two pointers. For that, you should put the parentheses thus:
node *(children[2]);
which then reads as: the contents of children are an applying * on one of them yields a node. This is what you want: an array of two pointers to node. Note that this is equivalent to:
node *children[2];
because in the C syntax, when it comes to type expressions, the [] operator takes precedence over the * operator.
In your initial version, the C compiler grumbles because at the time it reads the declaration, it does not know what size node is (the structure definition is not complete yet), and, as such, has trouble imagining a type "array of two node". This is a rather indirect symptom of the problem.
Side note: you should refrain from using _node or any other identifier beginning with an underscore in your code. These identifiers are reserved for "the implementation". In practice, system headers may use them, and collisions could prove harmful. Personally, I tend to add the underscore at the end, like this: typedef struct node_
49.6k888145
Instead of this:
node (*children)[2];
struct _node* children[2];
28.4k1176130
Your Answer
Sign up or
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Post as a guest
By posting your answer, you agree to the
Not the answer you're looking for?
Browse other questions tagged
The week's top questions and answers
Important community announcements
Questions that need answers
By subscribing, you agree to the
Stack Overflow works best with JavaScript enabled相关文章推荐:
array type has incomplete element type
我在移植代码到hp(ia64 B.11.23)时编译出错,
编译器用的是gcc4.1.0,错误提示为:
In file included from /usr/include/sys/mp.h:53,
from /usr/include/sys/malloc.h:59,
from /usr/include/net/netmp.h:51,
from /usr/include/net/if.h:59,
/usr/include/machine/sys/getppdp.h:65: error: array type has incomplete element type
我在网络上查找答案,发现编译器gcc4.0....
阅读(2168) 回复(0)
其他文章推荐
我在移植代码到hp(ia64 B.11.23)时编译出错,
编译器用的是gcc4.1.0,错误提示为:
In file included from /usr/include/sys/mp.h:53,
from /usr/include/sys/malloc.h:59,
from /usr/include/net/netmp.h:51,
from /usr/include/net/if.h:59,
/usr/include/machine/sys/getppdp.h:65: error: array type has incomplete element type
我在网络上查找答案,发现编译器gcc4.0....
阅读(2889) 回复(0)
If a specifier with a tag but without a list appears when the tag is not declared, an incomplete type is specified. Objects with an incomplete structure or union type may be mentioned in contexts where their size is not needed, for example in declarations (not definitions), for specifying a pointer, or for creating a typedef, but not otherwise. The type becomes complete on occurrence of a subseque...
阅读(1626) 回复(4)
在测试ioctl时,编译测试程序,出现:my_scull.h:51: error: field ‘my_scull_cdev’ has incomplete typemy_scull.h:52: error: field ‘sem’ has incomplete type出现此问题是因为在用户空间误用了内核空间的东西,在用户空间这些是不被认识的。可自己写一个头文件,把想要的写到里面,与内核空间的东西分离开就可以解决了。
阅读(1043) 回复(0)
#include <ctype.h>
// For bool, false, true
// For strcmp()
struct Family * get_person(void);
struct Famliy *pmember1;
struct Family *pmember2;
bool set_ancestry_fuck(struct Famliy *pmember1, struct Family *pmember2);
struct Date
struct Family
阅读(1959) 回复(6)
incomplete sype
可以看到string的定义,
如果想看到
该怎么作阿? 谢谢![code]#include
int main()
out("test.txt");
string str("nihao");
ss << "3\n";
ss << "this is ss...
阅读(4510) 回复(4)
dereferencing pointer to incomplete type
dereferencing pointer to incomplete type
的错误也是未包含某些头文件造成的!
分析数据包:判断通信双方的操作系统、网络信息流量、通过路由的数据包大小、数据包内容。
以太网:以太网的桢?
以太网中,数据是以被称为帧的数据结构本为单位进行交换的。
现在最常用的帧格式MAC V2
v2帧的格式:
(插入8字节)目的地址(6字节)-源地址(6字节)-类型(2字节)-数据(46-150...
阅读(1122) 回复(0)
我在aix5l , db2 8.1 上编译时,cc 报
incomplete type is not allowed 是什么意思啊,我的程序在其他的环境上是没有问题的,
而且 cc 是说 mytest.sqc 的 sqlca.sqlcode 好象有问题。程序代码如下:
#include ;
#include ;
#include ;
EXEC SQL INCLUDE
EXEC SQL BEGIN DECLARE SECTION:
EXEC SQL end
DECLARE SECTION:
EXEC SQL CONNECT TO :dbname
阅读(2560) 回复(0)
阅读(1453) 回复(2)
我反复检查了代码,是没有错的。
在网上简单搜了一下,说是头文件包含的问题。
我这网络访问受限,百度快照都打不开,只能跑这来问问了。
好心人给指点个迷津。:lol:
阅读(12243) 回复(10)
我把2.4下的一段代码移到2.6下,但是在编译到调用LIST_FIND()的时候报这个错:
dereferencing pointer to incomplete type
请问下,是什么问题阿
代码如下:
#include <linux/types.h>
#include <net/ch...
阅读(2863) 回复(1)
盛拓传媒:
北京皓辰网域网络信息技术有限公司. 版权所有
北京市公安局海淀分局网监中心备案编号:
广播电视节目制作经营许可证:编号(京)字第1149号
ITPUB推荐文章解答你所有技术难题------解决方案--------------------不知道是不是这个效果
/*&ex11,&ch&14&*/
#include&&stdio.h&
#include&&math.h&
#define&NUM
#define&VAR
typedef&double&(*FUN)(double);&
void&transform(double*&,&double*&,&int,&double&(*)(double));
double&twice(double);
double&half(double);
int&main(void)
double&source[NUM]&=&{0.1,&1.2,&2.3,&3.4,&4.5,&5.6,&6.7,&7.8,&8.9,&9.0};
double&target[NUM];
FUN&funcs[VAR]&=&{sqrt,&sin,&twice,&half};&
&&&&&&&&int&i;
for(&i&=&0;&i&&&VAR;&i++)&&&&&&&
&&&&transform(source,&target,&NUM,&funcs[i]);
&&&&return&0;
void&transform(double*&source,&double*&target,&int&n,&double&(*func)(double))
&&&&int&i;
&&&&for(&i&=&0;&i&&&n;&i++)
&&&&&&&&target[i]&=&func(source[i]);
double&twice(double&x)
&&&&return&2.0&*&x;
double&half(double&x)
&&&&return&x/2.0;
------解决方案--------------------typedef&double&(*FUN)(double);&
for(int&i&=&0;&i&&&VAR;&i++)
if(funcs[i]&!=&NULL)
for(int&j&=&0;&j&&&NUM;&j++)
transform(source[j],&target[j],&NUM,&funcs[i]);
}------解决方案--------------------
typedef&double&(*FUN)(double);
void&transform(double&,&double&,&int,&FUN&func);
double&twice(double);
double&half(double);
int&main(void)
&&&&int&i,j;&
&&&&double&source[NUM]&=&{0.1,&1.2,&2.3,&3.4,&4.5,&5.6,&6.7,&7.8,&8.9,&9.0};&20&&&&
double&target[NUM];
&&&&FUN&abc[VAR]&=&{sqrt,&sin,&twice,&half};
&&&&for(i&=&0;&i&&&VAR;&i++) 共&2&页:
12345678910
12345678910
12345678910 上一篇:下一篇:文章评论相关解决方案 12345678910 Copyright & &&版权所有关于一个函数指针数组(error: array type has incomplete element type)
[问题点数:40分,结帖人mcmay]
关于一个函数指针数组(error: array type has incomplete element type)
[问题点数:40分,结帖人mcmay]
不显示删除回复
显示所有回复
显示星级回复
显示得分回复
只显示楼主
2014年10月 C/C++大版内专家分月排行榜第三2014年4月 C/C++大版内专家分月排行榜第三
匿名用户不能发表回复!|
每天回帖即可获得10分可用分!小技巧:
你还可以输入10000个字符
(Ctrl+Enter)
请遵守CSDN,不得违反国家法律法规。
转载文章请注明出自“CSDN(www.csdn.net)”。如是商业用途请联系原作者。

我要回帖

更多关于 elementtype 的文章

 

随机推荐