掃二維碼與項(xiàng)目經(jīng)理溝通
我們?cè)谖⑿派?4小時(shí)期待你的聲音
解答本文疑問(wèn)/技術(shù)咨詢(xún)/運(yùn)營(yíng)咨詢(xún)/技術(shù)建議/互聯(lián)網(wǎng)交流
C語(yǔ)言是一門(mén)廣泛使用的計(jì)算機(jī)編程語(yǔ)言,它有著嚴(yán)格的語(yǔ)法規(guī)則,在編寫(xiě)C語(yǔ)言程序時(shí),經(jīng)常會(huì)遇到各種各樣的錯(cuò)誤,下面列舉了一些常見(jiàn)的C語(yǔ)言報(bào)錯(cuò)代碼及其解釋?zhuān)詭椭_(kāi)發(fā)者理解和解決這些問(wèn)題。

1、編譯時(shí)錯(cuò)誤:
error: expected ';' before '}' token
解釋?zhuān)涸诨ɡㄌ?hào) } 之前應(yīng)該有一個(gè)分號(hào) ; 來(lái)結(jié)束一條語(yǔ)句。
error: expected expression before ')' token
解釋?zhuān)涸谟依ㄌ?hào) ) 之前應(yīng)該有一個(gè)表達(dá)式。
error: 'function' was not declared in this scope
解釋?zhuān)涸诋?dāng)前作用域中沒(méi)有找到名為 function 的函數(shù)聲明。
error: 'variable' was not declared in this scope
解釋?zhuān)涸诋?dāng)前作用域中沒(méi)有找到名為 variable 的變量聲明。
error: 'struct' has no member named 'member'
解釋?zhuān)涸诿麨?struct 的結(jié)構(gòu)體中沒(méi)有找到名為 member 的成員。
error: array type has incomplete element type 'struct'
解釋?zhuān)簲?shù)組的元素類(lèi)型為未完整定義的結(jié)構(gòu)體 struct。
2、鏈接時(shí)錯(cuò)誤:
undefined reference to 'function'
解釋?zhuān)涸阪溄訒r(shí)找不到名為 function 的函數(shù)定義。
undefined reference to symbol 'symbol'
解釋?zhuān)涸阪溄訒r(shí)找不到名為 symbol 的符號(hào)定義。
multiple definition of 'variable'
解釋?zhuān)鹤兞?variable 在多個(gè)文件中定義了多次。
ld returned 1 exit status
解釋?zhuān)烘溄悠鲌?zhí)行失敗,返回了退出狀態(tài) 1。
3、運(yùn)行時(shí)錯(cuò)誤:
Segmentation fault
解釋?zhuān)撼绦蛟噲D訪問(wèn)一個(gè)它沒(méi)有權(quán)限訪問(wèn)的內(nèi)存段。
Bus error
解釋?zhuān)撼绦蛟噲D訪問(wèn)非法的物理內(nèi)存地址。
Floating point exception
解釋?zhuān)撼绦蛟趫?zhí)行浮點(diǎn)運(yùn)算時(shí)出現(xiàn)了錯(cuò)誤。
Abort
解釋?zhuān)撼绦蛞驗(yàn)槟承﹪?yán)重的錯(cuò)誤而異常終止。
Stack overflow
解釋?zhuān)撼绦蛴猛炅藯?臻g,導(dǎo)致棧溢出。
4、語(yǔ)法錯(cuò)誤:
error: expected identifier or '(' before numeric constant
解釋?zhuān)涸跀?shù)字常量之前應(yīng)該有一個(gè)標(biāo)識(shí)符或左括號(hào) (。
error: expected ')' before 'type'
解釋?zhuān)涸陬?lèi)型 type 之前應(yīng)該有一個(gè)右括號(hào) )。
error: expected declaration specifiers before 'identifier'
解釋?zhuān)涸跇?biāo)識(shí)符 identifier 之前應(yīng)該有聲明說(shuō)明符。
error: 'token' : undeclared identifier
解釋?zhuān)何绰暶鳂?biāo)識(shí)符 token。
error: 'token' : syntax error
解釋?zhuān)涸?token 處出現(xiàn)了語(yǔ)法錯(cuò)誤。
5、類(lèi)型錯(cuò)誤:
error: invalid conversion from 'type1' to 'type2'
解釋?zhuān)簭念?lèi)型 type1 到類(lèi)型 type2 的轉(zhuǎn)換無(wú)效。
error: cannot convert 'type1' to 'type2' in initialization
解釋?zhuān)涸诔跏蓟瘯r(shí)無(wú)法將類(lèi)型 type1 轉(zhuǎn)換為類(lèi)型 type2。
error: passing 'type1' as argument 1 of 'function' with mismatched parameter type 'type2'
解釋?zhuān)簩㈩?lèi)型 type1 作為參數(shù) 1 傳遞給函數(shù) function,與參數(shù)類(lèi)型 type2 不匹配。
error: 'type1' to 'type2' conversion may lose significant bits
解釋?zhuān)簭念?lèi)型 type1 到類(lèi)型 type2 的轉(zhuǎn)換可能會(huì)丟失重要的位。
以上僅列舉了部分常見(jiàn)的C語(yǔ)言報(bào)錯(cuò)代碼及其解釋?zhuān)趯?shí)際編程過(guò)程中,可能還會(huì)遇到更多其他類(lèi)型的錯(cuò)誤,遇到錯(cuò)誤時(shí),開(kāi)發(fā)者需要根據(jù)錯(cuò)誤信息,逐步定位問(wèn)題,并采取相應(yīng)措施解決,通過(guò)不斷積累經(jīng)驗(yàn),開(kāi)發(fā)者將能夠更好地理解和掌握C語(yǔ)言編程。

我們?cè)谖⑿派?4小時(shí)期待你的聲音
解答本文疑問(wèn)/技術(shù)咨詢(xún)/運(yùn)營(yíng)咨詢(xún)/技術(shù)建議/互聯(lián)網(wǎng)交流