是什么导致程序编译错误?望达人指教

madgod 2006-08-28 10:47:46
小弟写了一个简单的C程序,功能是从文本文件中提取符合条件的记录,我使用链表来存储这些记录。现在的问题是,程序在gcc下始终无法通过编译,报以下错误:(该代码可以在vc下正常编译运行,只是gcc编译通不过)
tjbillinputcash.c:33: error: parse error before '&' token
tjbillinputcash.c:70: error: parse error before '&' token
tjbillinputcash.c: In function `AddRecord':
tjbillinputcash.c:75: error: `pListHead' undeclared (first use in this function)
tjbillinputcash.c:75: error: (Each undeclared identifier is reported only once
tjbillinputcash.c:75: error: for each function it appears in.)
tjbillinputcash.c:78: error: `rec' undeclared (first use in this function)
tjbillinputcash.c:85: error: `pListTail' undeclared (first use in this function)

相关代码清单:
#include <stdio.h>
#include <malloc.h>
#include <string.h>

/********************************************************************
错误交易记录的结构,从日志文件中解析获得字段值
********************************************************************/
typedef struct REC
{
char loginname[20];
char serverip[15];
uint itemid;
struct REC* next;
}_REC;

/********************************************************************
函数声明
********************************************************************/
int recCmp( const void* pvRec1, const void* pvRec2 );
void AddRecord( struct REC*& pListHead, struct REC*& pListTail, REC& rec );//33行

int recCmp( const void* pvRec1, const void* pvRec2 )
{
……
}

void AddRecord( struct REC*& pListHead, struct REC*& pListTail, struct REC& rec ) //70行
{
if( !pListHead ) // 如果列表为空 //75行
{
// 给列表创建第一个元素
pListHead = (struct REC*)malloc( sizeof(rec) ); //78行

strcpy( pListHead->loginname, rec.loginname );
strcpy( pListHead->serverip, rec.serverip );
pListHead->itemid = rec.itemid;
pListHead->next = NULL;

pListTail = pListHead; //85行
return;
}
else
{
……
}
……
}

int main( int argc, char* argv[] )
{
……
}



望达人指教,在线等
...全文
251 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
fytzzh 2006-08-28
  • 打赏
  • 举报
回复
如果使用gcc编译器就不能使用c++语法里的引用。修改如下:
typedef struct REC
{
char loginname[20];
char serverip[15];
uint itemid; ===================》换成unsigned int itemid;
struct REC* next;
}_REC;

void AddRecord( struct REC*& pListHead, struct REC*& pListTail, REC& rec );//33行
改为
void AddRecord( struct REC* pListHead, struct REC* pListTail, struct REC rec );//33行

void AddRecord( struct REC*& pListHead, struct REC*& pListTail, struct REC& rec ) //70行
改为:
void AddRecord( struct REC* pListHead, struct REC* pListTail, struct REC rec ) //70行

如果想使用c++语法里的引用的话,将tjbillinputcash.c文件改问tjbillinputcash.cc或tjbillinputcash.cpp 使用g++编译器
源码直接下载地址: https://pan.quark.cn/s/a4b39357ea24 平台简介 License Spring Boot JDK-17 本项目基于ruoyi-vue-fast实现 项目代码、文档 均开源免费可商用 遵循开源协议在项目中保留开源协议文件即可 活到老写到老 为兴趣而开源 为学习而开源 为让大家真正可以学到技术而开源 若依wms是一套基于若依的wms仓库管理系统,支持lodop和网页打印入库单、出库单。 毫无保留给个人及企业免费使用。 前端采用Vue、Element UI。 后端采用Spring Boot、Spring Security、Redis & Jwt。 权限认证使用Jwt,支持多终端认证系统。 支持加载动态权限菜单,多方式轻松权限控制。 高效率开发,使用代码生成器可以一键生成前后端代码。 前端项目地址 gitee https://gitee.com/zccbbg/ruo-yi-wms-vue https://.com/zccbbg/RuoYi-WMS-VUE 若依实战技术专栏 关注文末公众号回复:星球 在线体验 https://wms.ichengle.top/ 不同分支介绍 jdk17+vue3,支持多仓库,没有库区概念,操作简单,覆盖大部分库存应用场景。 jdk17+vue3,支持多仓库、多库区,记录生产日期、过期日期、sn,可适配一物一码,操作相对复杂。 jdk8+vue2 同步lite分支 若依wms功能 首页:库存预警与到期提醒、基础数据报表展示 仓库/库区:管理维护仓库基础数据 物料:管理维护物料基础数据 客户/供应商:管理维护联系人基础数据 入库:创建入库单后包括如下几个状态:暂存、作废、完成入库,入库类型包括:采购...

23,224

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧