作者ho83leo (LWHo)
看板C_and_CPP
標題[問題] gcc 編譯器問題
時間Tue Dec 15 00:54:46 2015
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
gcc 4.9.2 and 4.9.3 and 5.2.0
linux gcc 4.9.2
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
問題(Question):
在windows 10 x64 安裝了 cygwin x86(因IDE因素所以上x86),
剛剛windows 編譯的時候, 可以安全safe, 但是印出後 卻是很長一段數值,
可是加總後的總數卻是正確的...
餵入的資料(Input):
五個參數 8 6 3.0 0.2 1.0
預期的正確結果(Expected Output):
在linux 執行結果為圖
https://goo.gl/4Xqcj9
錯誤結果(Wrong Output):
windows 10 cygwin x86 gcc 4.9.2 / 4.9.3 / 5.X.X 都同樣錯誤結果
https://goo.gl/tdyNCH
程式碼(Code):(請善用置底文網頁, 記得排版)
http://codepad.org/dOURJdAZ
補充說明(Supplement):
求各位大大解惑也!!!
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 120.102.146.202
※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1450112090.A.84F.html
推 LPH66: 你的 total 一開始沒有歸零, 後來是對的是因為 32 行歸零了 12/15 01:24
→ LPH66: 只宣告沒給初值的變數其內容不可預測 12/15 01:25
→ ho83leo: 感謝解答... 犯這種錯誤真是粗心 12/15 09:34