struct {
int item;
struct list* next;
}list;

如果结构体定义如上,使用下面的代码,将会报错

//添加元素,由于我们实现的是单向链表,所以使用从尾部添加
bool AddItem(int a,struct list *plist)
{
struct list *pNew;
struct list *pNode;
pNode=plist;
pNew=malloc(sizeof( struct list));
if(pNew==NULL)
{
return false;
}
pNew->item=a;
pNew->next=NULL;
if(pNode==NULL)
{
plist=pNew;
}else
{
while(pNode->next!=NULL)
{
pNode=pNode->next;
}
pNode->next=pNew;
}
return true;
}

  

c30.c: In function 'AddItem':
c30.c:30:22: error: invalid application of 'sizeof' to incomplete type 'struct list'
pNew=malloc(sizeof( struct list));
^
c30.c:35:6: error: dereferencing pointer to incomplete type
pNew->item=a;
^

其报错并不在struct处,而是在其使用处。

这是因为结构体定义有问题。

struct并不报错的更多相关文章

  1. VC中编译报错:error C2011: 'fd_set' : 'struct' type redefinition

    这是头文件包含顺序的问题,原因与解决办法见下面代码的注释. /* 包含下面这两个头文件时,必须把winsock2.h放在前面 否则编译报错,N多的重定义错误:例如 error C2011: 'fd_s ...

  2. 编译binutil包报错 error: array type has incomplete element type extern const struct relax_type md_relax_table[];

    安装lfs时编译binutils出错: ../../sources/binutils-2.15.91.0.2/gas/config/tc-i386.h:457:32: error: array typ ...

  3. python连接impala时,执行SQL报错expecting list of size 2 for struct args

    这个错误困扰了好久,因为集群有多台,暂放到其他几台机器上执行了SQL操作,一直在找解决方法,无意间得到真传,喜出望外啊 报错信息: Traceback (most recent call last): ...

  4. 编译器报错: error LNK2001: unresolved external symbol "struct _ServiceDescriptorTable * KeServiceDescript

    转自VC错误:http://www.vcerror.com/?p=10 问题描述: 编译器报错: error LNK2001: unresolved external symbol "str ...

  5. php5.6.11编译安装报错configure: error: Don't know how to define struct flock on this system

    centos 6.8 32位系统下,安装php.5.6.11是出现这个错误 解决办法: 1 2 3 4 vim /etc/ld.so.conf.d/local.conf     # 编辑库文件 /us ...

  6. Openwrt 编译报错:rootfs image is too big解决方法

    修改: tools/firmware-utils/src/mktplinkfw2.c static struct flash_layout layouts[] = { { .id = "8M ...

  7. 关于编译报错“dereferencing pointer to incomplete type...

    今天同事问了我一个问题,他make的时候报错,“第201行:dereferencing pointer to incomplete type”,我随即查阅了很多资料,也没看出个所以然.最后问题得到了解 ...

  8. Ubuntu gcc编译报错:format ‘%llu’ expects argument of type ‘long long unsigned int’, but argument 2 has type ‘__time_t’ [-Wformat=]

    平时用的都是Centos系统,今天偶然在Ubuntu下编译了一次代码,发现报错了: 源码: #include <stdio.h> #include <sys/time.h> # ...

  9. 解决oralce 11g dg搭建报错:ORA-16664、ORA-16714、ORA-16810问题--转

    下面不是小编错误报告只是转了网络一篇,同时也解决了我的问题所以复制过来给各位参考. 最近在弄11g的dg时,遇到如下问题,记录下.首先在主上查看报如下错误: DGMGRL> show confi ...

随机推荐

  1. vue-cli3项目关闭烦人的代码检测

    参考博客:https://blog.csdn.net/e1172090224/article/details/99636767 vue.config.js module.exports = { lin ...

  2. 《设计模式》读懂UML类图

    一.类中的主要关系 继承.实现.组合.聚合.依赖.关联 二.UML类图 三.代码实现 public class H2O { } public class O2 { } public interface ...

  3. APT33追踪思路

    APT33组织主要针对石油和航空业,这个组织使用了大约十二个命令与控制服务器(C&C)针对性的对目标攻击.APT33也一直在做定点针对性攻击.比如近两年来,该组织利用一位欧洲高级政治人物(该国 ...

  4. 【C/C++开发】C++11:左值引用VS右值引用

    左值引用VS右值引用 左值引用对于一般的C++程序员再熟悉不过,但对于右值引用(C++0X新特性),就稍微有点不知所云 左值VS右值 在定义变量的时候,经常会用到左值和右值,比如:int a = 1; ...

  5. jquery如何生成图片验证码

    jQuery(function($){ /**生成一个随机数**/ function randomNum(min, max) { return Math.floor(Math.random() * ( ...

  6. PHP对二维数组进行排序

    /** * 获取最近的店铺 * @param $lng * @param $lat * @return array */ protected function getClosestShop($lng, ...

  7. for循环与if条件语句的复习运用

    鉴于前面学了不少基础了,今天没有学新的内容.boyfriend给我出了几道简单的题目,慢慢的进步中. 1.# 计算1-100之间所有偶数的和 def sum(): sumone = 0 for i i ...

  8. Html设置问题(设置浏览器上面的图标,移动设备上面页面保存为图标)

    最近开发了一个新的项目,项目完成之后:要求把页面在移动设备上面保存为图标,通过图标直接进入系统入口(这样看着就想APP一样):刚开始通过百度直接设置了,发现有两个问题,第一.图标直接是页面的截图:第二 ...

  9. JDK提供的并发工具类

    1.CountDownLatch await(),进入等待的状态 countDown(),计数器减一 应用场景:启动三个线程计算,需要对结果进行累加. /** * * CountDownLatch D ...

  10. oracle学习笔记(三)

    索引: drop table test1 purge; drop table test2 purge; drop table test3 purge; drop table t purge; crea ...