[問題] 請問在編譯時如何知道變數大小????

看板C_and_CPP (C/C++)作者 (ckvir)時間13年前 (2012/09/03 16:45), 編輯推噓0(008)
留言8則, 4人參與, 最新討論串1/1
開發平台(Platform): (Ex: VC++, GCC, Linux, ...) Linux 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...) 問題(Question): 目前我編譯一個檔案 但總是會出錯 訊息為warning: cast from pointer to integer of different size 其中錯誤那行為b_add = (uint16_t) baseArea; 我想可能是做cast時 兩變數大小不一樣 但問題是 要用什麼方法知道這兩變數的大小??? 因為編譯時用print sizeof也顯示不出來 但是整個檔案太大 也不知道定義變數時多大 所以有什麼方法比較容易在編譯不成功時debug?? 謝謝 餵入的資料(Input): 預期的正確結果(Expected Output): 錯誤結果(Wrong Output): 程式碼(Code):(請善用置底文網頁, 記得排版) 補充說明(Supplement): -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.120.15.253

09/03 16:50, , 1F
如果只是warning的話,應該還是會編譯過阿
09/03 16:50, 1F

09/03 16:50, , 2F
你的問題會不會在別的地方?
09/03 16:50, 2F

09/03 16:55, , 3F
指標大小可能是 32bits 的,你用16bits的型別可能會錯
09/03 16:55, 3F

09/03 16:56, , 4F
所以噴出了....... 一個警告
09/03 16:56, 4F

09/03 16:57, , 5F
大部分是跟 long 一樣長, 不過不一定
09/03 16:57, 5F

09/03 18:47, , 6F
他都說cast from pointer to integer of different size
09/03 18:47, 6F

09/03 18:48, , 7F
很明顯是從[pointer]轉到[不同大小的整數]所以有錯誤
09/03 18:48, 7F

09/03 18:48, , 8F
不要用想的。用看的就好。
09/03 18:48, 8F
文章代碼(AID): #1GH6ua7y (C_and_CPP)
文章代碼(AID): #1GH6ua7y (C_and_CPP)