[問題] xcode與Visual Studio結果不同

看板C_and_CPP作者 (micky)時間8年前 (2015/11/07 17:51), 8年前編輯推噓4(407)
留言11則, 5人參與, 最新討論串1/1
開發平台(Platform): (Ex: VC++, GCC, Linux, ...) Xcode & Visual Studio 2010 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...) 問題(Question): 兩者結果不同 VC++: http://imgur.com/pxTWyMb
Xcode: http://imgur.com/gAG4F0g
餵入的資料(Input): lena.bmp (8bits,512*512) http://imgur.com/o4kWisP
預期的正確結果(Expected Output): VC++才是預期結果, 用dev c++也是一樣的結果, 但xcode究竟哪裡錯了QQ 錯誤結果(Wrong Output): 如問題處QQ 程式碼(Code):(請善用置底文網頁, 記得排版) http://codepad.org/6s9RTkek 補充說明(Supplement): 希望有人能幫我解決這問題QQ 不管怎麼重開project, 重開機 都無法變成正確的圖Orz 先謝謝各位Q______Q -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 111.251.225.175 ※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1446889880.A.457.html

11/07 18:26, , 1F
A,B,C,D,E,F,G......................
11/07 18:26, 1F
嗚嗚我知道矩陣設得亂七八糟QQQQQ 但是我有寫註解希望有人能有辦法解決QQQQQ ※ 編輯: micky64 (111.251.225.175), 11/07/2015 18:35:22

11/07 20:59, , 2F
看code猜測是因為struct大小不同 可以google關鍵字
11/07 20:59, 2F

11/07 20:59, , 3F
c attribute packed
11/07 20:59, 3F

11/07 21:12, , 4F
建議遇到這類問題時 可以先一步步追蹤值到哪裡不符合預期
11/07 21:12, 4F

11/07 21:13, , 5F
樓上說的struct alignment的問題是有可能的
11/07 21:13, 5F

11/07 21:45, , 6F
一樣都是 64 bit 的程式,Windows 的 unsigned long
11/07 21:45, 6F

11/07 21:46, , 7F
會是 4 bytes,但是在 UNIX-like 下會是 8 bytes
11/07 21:46, 7F

11/07 21:46, , 8F
請 #include <stdint.h> 然後改用 uint32_t 來描述 BMP
11/07 21:46, 8F

11/07 21:51, , 9F
我相信問題自然就會消失,有興趣可以自己印一下大小
11/07 21:51, 9F

11/07 23:18, , 10F
unsigned long全改成uint32_t試試
11/07 23:18, 10F

11/07 23:20, , 11F
c,c++讀檔和網路傳輸,最好不要用int,long,char之類的型別啦
11/07 23:20, 11F
文章代碼(AID): #1MFScOHN (C_and_CPP)