看板 C_and_CPP 關於我們 聯絡資訊
開發平台(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
Hazukashiine: 你 warning 有看了沒? 07/31 04:14
Hazukashiine: short* 硬轉 double* 我不信編譯器沒報警告 07/31 04:15
Hazukashiine: 轉 int* 會對是 data model 設計的寬度一樣而已 07/31 04:17
wei115: ieee754 07/31 04:41
MOONRAKER: 真有創意的轉法。 07/31 15:34
adrianshum: 轉int會成功只是因為你在little endian 的平台吧。 bi 08/01 20:47
adrianshum: g endian 會出現0 (不 core dump 的話) 08/01 20:47