[問題] typedef在不同平台上編譯產生的錯誤

看板C_and_CPP作者 (珍惜及時擁有的幸福)時間12年前 (2012/01/09 22:23), 編輯推噓1(105)
留言6則, 2人參與, 最新討論串1/1
開發平台(Platform): (Ex: VC++, GCC, Linux, ...) VC++ 6 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...) 問題(Question): c檔的函式內容 /* show the all packet information in queue */ int show_q(LinkQueue *Q) { int seq_q = 1; printf("// Show the packet information in queue //\n"); Queue *p = (Queue *)malloc(sizeof(Queue)); p = Q->front->next; while(p!=NULL) { printf("(%d) sequence number: %2d, packet size: %d, arrival time: %d\n", seq_q, p->packet.sn, p->packet.pkt_size, p->packet.arr_time); //system("PAUSE"); p = p->next; seq_q++; } free(p); return 1; } h檔的內容 typedef struct QNode { PktStr packet; struct QNode *next; }Queue; 餵入的資料(Input): 預期的正確結果(Expected Output): 原先在Dev C執行正確,不過放到VC++ 6就出現以下錯誤訊息 錯誤結果(Wrong Output): e:\pclin\會議集(meetingfolders)\2012-01-11 handover simulation code\llq_vc\llq.c(114) : error C2275: 'Queue' : illegal use of this type as an expression e:\pclin\會議集(meetingfolders)\2012-01-11 handover simulation code\llq_vc\llq.h(22) : see declaration of 'Queue' e:\pclin\會議集(meetingfolders)\2012-01-11 handover simulation code\llq_vc\llq.c(114) : error C2065: 'p' : undeclared identifier e:\pclin\會議集(meetingfolders)\2012-01-11 handover simulation code\llq_vc\llq.c(115) : warning C4047: '=' : 'int ' differs in levels of indirection from 'struct QNode *' e:\pclin\會議集(meetingfolders)\2012-01-11 handover simulation code\llq_vc\llq.c(116) : warning C4047: '!=' : 'int ' differs in levels of indirection from 'void *' e:\pclin\會議集(meetingfolders)\2012-01-11 handover simulation code\llq_vc\llq.c(118) : error C2223: left of '->packet' must point to struct/union e:\pclin\會議集(meetingfolders)\2012-01-11 handover simulation code\llq_vc\llq.c(118) : error C2223: left of '->packet' must point to struct/union e:\pclin\會議集(meetingfolders)\2012-01-11 handover simulation code\llq_vc\llq.c(118) : error C2223: left of '->packet' must point to struct/union e:\pclin\會議集(meetingfolders)\2012-01-11 handover simulation code\llq_vc\llq.c(120) : error C2223: left of '->next' must point to struct/union e:\pclin\會議集(meetingfolders)\2012-01-11 handover simulation code\llq_vc\llq.c(123) : warning C4022: 'free' : pointer mismatch for actual parameter 1 Error executing cl.exe. 程式碼(Code):(請善用置底文網頁, 記得排版) 補充說明(Supplement): 想請問是我宣告的方式錯誤嗎?可以請厲害的大大指點嗎@@ -- 幹!回家了啦!別在這裡丟人現眼了 我還沒說完吶~~ ○ ︵ \○╱/| . . ﹎ ﹍﹍ ╱ ̄﹚╱> -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.118.122.107

01/09 22:36, , 1F
將檔案放到路徑中沒中文也沒空格的呢?
01/09 22:36, 1F

01/09 22:37, , 2F
或是換2008或2010不知道能不能
01/09 22:37, 2F

01/10 00:43, , 3F
把printf("// Show the pack... 和 Queue *p = ...對掉
01/10 00:43, 3F

01/10 00:45, , 4F
宣告先寫完 再寫statement
01/10 00:45, 4F

01/10 00:46, , 5F
懶一點就是把副檔名.c改成.cpp
01/10 00:46, 5F

01/10 10:43, , 6F
因為c要求宣告要在最上面一次宣告嗎?
01/10 10:43, 6F
文章代碼(AID): #1F2lXE-I (C_and_CPP)