[問題] void*與void**差異?
開發平台(Platform): (Ex: Win10, Linux, ...)
Linux
編譯器(Ex: GCC, clang, VC++...)+目標環境(跟開發平台不同的話需列出)
gcc x64 4.8.3 或4.8.5
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
問題(Question):
使用void** 與void*結果不一致
不曉得是compiler bug或是shared memory的address是否有地雷
餵入的資料(Input):
可以使用
python -c 'print("\x55\xAA\x55\xAA")' > struct.bin
產生測資 檔名一定要struct.bin
預期的正確結果(Expected Output):
執行以下兩行程式片段應該一樣結果
以下是call兩個不同函數
load_table_from_shm_voidpp((void**)&g_test_struct);
load_table_from_shm_voidp((void*)g_test_struct);
錯誤結果(Wrong Output):
load_table_from_shm_voidp((void*)g_test_struct);
執行到read會取得errno=14 bad address
用gdb看bt, 傳入的void*會是(void*)0
程式碼(Code):(請善用置底文網頁, 記得排版)
gist
https://gist.github.com/swt02026/d6bafca53b375e62d807c33f33a0b694
補充說明(Supplement):
因為是公司的程式碼
所以我修改成最小能重現相同狀況的程式碼
編譯參數要加上 -std=gnu11
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 1.162.42.220
※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1503932763.A.ECC.html
推
08/28 23:57, , 1F
08/28 23:57, 1F
→
08/28 23:57, , 2F
08/28 23:57, 2F
→
08/29 00:02, , 3F
08/29 00:02, 3F
推
08/29 00:35, , 4F
08/29 00:35, 4F
→
08/29 07:25, , 5F
08/29 07:25, 5F
→
08/29 07:25, , 6F
08/29 07:25, 6F
function名稱好像取的不是很好
推文好像都以為是同一個function....
※ 編輯: soheadsome (223.137.244.234), 08/29/2017 07:31:50
※ 編輯: soheadsome (223.137.244.234), 08/29/2017 07:33:19
→
08/29 07:53, , 7F
08/29 07:53, 7F
這是我的問題 大家都用手機 取太像會分不清
※ 編輯: soheadsome (223.137.244.234), 08/29/2017 08:01:29
推
08/29 08:24, , 8F
08/29 08:24, 8F
→
08/29 08:24, , 9F
08/29 08:24, 9F
→
08/29 08:24, , 10F
08/29 08:24, 10F
→
08/29 08:37, , 11F
08/29 08:37, 11F
喔喔 我了解了
我傳入的時候g_test_struct 還沒指到shm
傳入table就會是還沒初始化的舊值
感謝<(_ _)>
※ 編輯: soheadsome (223.137.244.234), 08/29/2017 08:47:12
→
08/29 08:47, , 12F
08/29 08:47, 12F
→
08/29 08:47, , 13F
08/29 08:47, 13F