專注電子技術(shù)學(xué)習(xí)與研究
當(dāng)前位置:單片機(jī)教程網(wǎng) >> MCU設(shè)計實(shí)例 >> 瀏覽文章

error: expected ‘=’, ‘,’, ‘;’, ‘a(chǎn)sm’ or ‘__attribute__‘問題解決

作者:huqin   來源:本站原創(chuàng)   點(diǎn)擊數(shù):  更新時間:2014年03月13日   【字體:

今天寫了一段比較簡單的C語言程序,但是在編譯的時候卻遇到了一個不怎么常見的錯誤,特此做一個簡單的總結(jié)。
 
我采用gcc編譯的過程中出現(xiàn)了如下的一些錯誤:
[gong@Gong-Computer hashmap]$ gcc -g testlist.c list.c -o testlist
In file included from testlist.c:3:0:
list.h:28:6: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘create_list’
list.h:29:6: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘insert_listnode’
list.h:30:6: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘delete_listnode’
In file included from list.c:4:0:
list.h:28:6: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘create_list’
list.h:29:6: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘insert_listnode’
list.h:30:6: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘delete_listnode’
list.c:6:13: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘create_listnode’
list.c:19:6: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘create_list’
list.c:33:6: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘insert_listnode’
list.c:76:6: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘delete_listnode’
這種錯誤在我前面寫代碼的時候很少看見,我也不知道是怎么了,然后我又采用g++的編譯器進(jìn)行了一次編譯,竟然通過了。所以我覺得肯定是編譯器存在問題。
 
這個讓我有些不知所措,通過查找網(wǎng)頁,發(fā)現(xiàn)了這個問題出現(xiàn)的原因。
 
出現(xiàn)這種錯誤是因?yàn)閎ool類型錯誤,因?yàn)槲以诔绦蛑蟹祷亓薴alse,true以及bool類型,但是在C語言中是不存在布爾類型的數(shù)據(jù)的,這就是出現(xiàn)錯誤的原因。
 
找到的原因通過宏定義即可解決上面出現(xiàn)的問題:
#define bool int
#define true 1
#define false 0
 
添加好這幾個宏定義以后,編譯器竟然沒有問題了。

關(guān)閉窗口

相關(guān)文章