clang 的詭異之處

2021-06-20 23:30:41 字數 3042 閱讀 3926

最近一次作業,寫乙個高精度+ - × / 運算

當然寫的時候有點小錯誤,程式執行一直失敗,在除錯的時候居然發現一件詭異的事情

我個人認為是clang++有問題,但通常說clang++編譯更嚴格,也可能是我寫法的問題

望各位指正

amrzs@ubuntu:bigint$ g++ -g main.cpp bigint.cpp -o gtst

amrzs@ubuntu:bigint$ clang++ -g main.cpp bigint.cpp -o ctst

amrzs@ubuntu:bigint$ gdb gtst

gnu gdb (gdb) 7.6.1-ubuntu

license gplv3+: gnu gpl version 3 or later this is free software: you are free to change and redistribute it.

there is no warranty, to the extent permitted by law. type "show copying"

and "show warranty" for details.

this gdb was configured as "x86_64-linux-gnu".

for bug reporting instructions, please see:

...reading symbols from /home/amrzs/workspace/py3/security/bigint/gtst...done.

(gdb) b 48

breakpoint 1 at 0x400cbd: file main.cpp, line 48.

(gdb) r

starting program: /home/amrzs/workspace/py3/security/bigint/gtst

2000000000

10010

2000000000

3100

breakpoint 1, main () at main.cpp:49

49 bigint result = a / b;

(gdb) s

bigint::operator/ (this=0x7fffffffc720, x=...) at bigint.cpp:104

104 bigint result;

(gdb) n

105 result.clear(); //make result being zero

(gdb) n

107 if(size < x.size)

(gdb) p result

$1 = }

(gdb) q

amrzs@ubuntu:bigint$ gdb ctst

gnu gdb (gdb) 7.6.1-ubuntu

license gplv3+: gnu gpl version 3 or later this is free software: you are free to change and redistribute it.

there is no warranty, to the extent permitted by law. type "show copying"

and "show warranty" for details.

this gdb was configured as "x86_64-linux-gnu".

for bug reporting instructions, please see:

...reading symbols from /home/amrzs/workspace/py3/security/bigint/ctst...done.

(gdb) b 48

breakpoint 1 at 0x400e4d: file main.cpp, line 48.

(gdb) r

starting program: /home/amrzs/workspace/py3/security/bigint/ctst

2000000000

10010

2000000000

3100

breakpoint 1, main () at main.cpp:49

49 bigint result = a / b;

(gdb) s

bigint::operator/ (this=0x7fffffffd6d0, x=...) at bigint.cpp:104

104 bigint result;

(gdb) n

105 result.clear(); //make result being zero

(gdb) n

107 if(size < x.size)

(gdb) p result

$1 = }

(gdb) q

注意到clang++的這句了嗎

(gdb) p result

$1 = }

我執行了result.clear()的意思的清空當前的result,使得size = 1, arr全為0,然而在clang++中居然不是這樣

可以看到g++生成的檔案中是正確的

(gdb) p result

$1 = }

類的實現**是這樣的

void bigint::clear()

不過最後我用gdb把個g++生成的檔案除錯好了,然後用clang++編譯修改過的檔案,再執行,居然結果也對,真是詭異

不過我有個疑問,是不是clang++生成的執行檔案不能用gdb來除錯呢?兩者有衝突,clang++的有類似gdb的偵錯程式?

clang++是剛剛安裝的3.4版本,我的系統是ubuntu 13.10 x86_64

快排的詭異之處

如果in place做quick sort,選擇放置pivot的位置會影響到 細節。同樣的實現方式,選擇第乙個元素為pivot時,恢復pivot位置就得以hi為準。public class testquicksort quicksort arr,0,arr.length 1 for int i ar...

《Stanley博士的家2》中的詭異之處

今天發現原來玩過的乙個flash遊戲stanley博士的家有了第二部,玩過之後感覺非常好。就是其中有乙個地方很詭異,拿出來和大家分享一下。大意是這樣 遊戲中的 我 james偵探可以借助時空門回到以前的時光,於是遊戲中的錐子就變成了乙個問題。我 的車被未來的我用狙擊槍打爆了輪胎,暈了之後醒來在地上撿...

Clang提供的辦法

1.方法棄用警告 1 pragma clang diagnostic push 2 pragma clang diagnostic ignored wdeprecated declarations 3 result self sizewithfont font constrainedtosize s...