看板 C_and_CPP 關於我們 聯絡資訊
開發平台(Platform): (Ex: Win10, Linux, ...) linux 編譯器(Ex: GCC, clang, VC++...)+目標環境(跟開發平台不同的話需列出) gcc 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...) 問題(Question): 第一次用cppcheck 這個程式發現不管我如何寫都會出現syntax error 程式碼(Code):(請善用置底文網頁, 記得排版,禁止使用圖檔) 例如 for(int i=1;i<3;i++) printf("test"); 或是 int i; for(i=1;i<3;i++) printf("test"); 都一樣, 我以前寫mfc是沒遇過 請問一下cppcheck的for loop要如何寫才不會出現error? 補充說明(Supplement): -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 118.167.131.119 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1672899639.A.E3F.html
lingege321: n3是什麼 錯誤訊息請補上01/05 14:44
RichieRich: 錯誤訊息就寫這樣(error) syntax error01/05 16:10
RichieRich: 我懷疑是不是cppcheck 有bug01/05 16:11
※ 編輯: RichieRich (220.135.152.19 臺灣), 01/05/2023 16:30:33
Lipraxde: Online demo (cppcheck 2.8) 是沒有遇到你說的問題 01/05 16:59
tomsawyer: 會不會是你的“”"被改了 我打的三個都不一樣 01/05 17:00
Lipraxde: 恩...不過如果只用你給的這三行的話,沒放到 function 01/05 17:01
Lipraxde: body 內的話,是會看到 syntax error 01/05 17:01
RichieRich: 我只要把for loop 刪除就不會有錯誤了 01/05 18:04
Lipraxde: 那有沒有可能是文字編碼的問題呀? 01/05 18:13
Dracarys: 你也給個runnable example 01/05 19:28
LPH66: 給個完整程式碼 01/06 00:43
mikemike1021: 應該跟 Lipraxde 講的一樣,for 不能在全域中,prin 01/06 07:00
mikemike1021: tf 可以。你把他放進任意一個函數內試試看?void te 01/06 07:00
mikemike1021: st(){你的程式} 01/06 07:00
Dracarys: 最外層只能放declaration printf不是 01/06 08:20
mikemike1021: 上述只指在 cppcheck online demo 下,沒跳錯 01/06 08:45
Dracarys: 笑死 還真的欸 01/06 19:53
saladim: printf statement可以在放在全域中? 01/11 23:08
fatalfeel2: 試用linux coding style 重寫一次 再測 03/17 12:07