[問題] 有關 short 轉double 問題

看板C_and_CPP作者 (sss)時間6年前 (2018/07/31 02:55), 編輯推噓0(115)
留言7則, 4人參與, 6年前最新討論串1/1
開發平台(Platform): (Ex: Win10, Linux, ...) QT 5.10 編譯器(Ex: GCC, clang, VC++...)+目標環境(跟開發平台不同的話需列出) qt creator4.5.1 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...) 問題(Question): short tempData[10]; *(int *)tempData = 1; *(double *)&tempData[1]=100; qDebug() << " " << tempData[0]; qDebug() << " " << tempData[1]; 請問為什麼 轉int結果是對的 但是double 卻是0呢 c++新手 求各位幫幫我 感謝 其中qDebug 相當於 cout 預期的正確結果(Expected Output): 1 100 錯誤結果(Wrong Output): 1 0 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 218.35.154.241 ※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1532976920.A.C56.html

07/31 04:14, 6年前 , 1F
你 warning 有看了沒?
07/31 04:14, 1F

07/31 04:15, 6年前 , 2F
short* 硬轉 double* 我不信編譯器沒報警告
07/31 04:15, 2F

07/31 04:17, 6年前 , 3F
轉 int* 會對是 data model 設計的寬度一樣而已
07/31 04:17, 3F

07/31 04:41, 6年前 , 4F
ieee754
07/31 04:41, 4F

07/31 15:34, 6年前 , 5F
真有創意的轉法。
07/31 15:34, 5F

08/01 20:47, 6年前 , 6F
轉int會成功只是因為你在little endian 的平台吧。 bi
08/01 20:47, 6F

08/01 20:47, 6年前 , 7F
g endian 會出現0 (不 core dump 的話)
08/01 20:47, 7F
文章代碼(AID): #1RNryOnM (C_and_CPP)