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

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[] )
{
……
}



望达人指教,在线等
...全文
202 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++编译器

23,116

社区成员

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

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