2 回答

TA貢獻1719條經驗 獲得超6個贊
原因是 Go 鏈接到 libpthread,但你的 C 程序沒有。如果我添加-lpthread
到 gcc 參數,它也會打印不同的指針。因此,libpthread 定義了它自己的accept
并覆蓋了 libc 的(這是有道理的)。
我想出來的方法是,我在兩個程序中都插入了一個睡眠,然后翻查/proc/$pid/maps
以查看返回的指針引用的內容。這表明在 Go 的例子中,“當前”指針駐留在 libpthread 中?!罢嬲摹敝羔樋偸且?libc。

TA貢獻1852條經驗 獲得超1個贊
符號不會加載到內存中的固定地址;他們去裝載機決定放置它們的任何地方。
這是我在我的機器上多次運行你的 C 程序的輸出。
govind@Govind-PC:/mnt/c/Temp$ ./dlst
Real: 0x7f4b5f3127d0 Current: 0x7f4b5f26ee30
govind@Govind-PC:/mnt/c/Temp$ ./dlst
Real: 0x7f45727127d0 Current: 0x7f457266ee30
govind@Govind-PC:/mnt/c/Temp$ ./dlst
Real: 0x7fc3373127d0 Current: 0x7fc33726ee30
govind@Govind-PC:/mnt/c/Temp$ ./dlst
Real: 0x7f0e555127d0 Current: 0x7f0e5546ee30
govind@Govind-PC:/mnt/c/Temp$ ./dlst
Real: 0x7f2fdd9127d0 Current: 0x7f2fdd86ee30
govind@Govind-PC:/mnt/c/Temp$ ./dlst
Real: 0x7fec7db127d0 Current: 0x7fec7da6ee30
govind@Govind-PC:/mnt/c/Temp$ ./dlst
Real: 0x7f07de1127d0 Current: 0x7f07de06ee30
govind@Govind-PC:/mnt/c/Temp$
- 2 回答
- 0 關注
- 223 瀏覽
添加回答
舉報