linux在main函式結尾出現段錯誤的問題

2021-06-20 22:39:52 字數 435 閱讀 3046

專案中需要用到sqlite來儲存一些臨

時資料,sqlite本來我就不熟,還好老外的東西文件比較齊全。所以在這邊花的時間還不算長,最崩潰的是,除錯程式的時候出現在main函式的結尾出現了段錯誤。gdb 除錯了半天,也跟蹤不出來,core檔案也顯示在main函式的結尾。。

最終的問題竟然是 main函式內的乙個資料出現越界的情況,為了測試這個結論,我寫了如下程式

1 #include

2 #include

3 int main()

4 /* 這裡你可以做一些其事情,這裡的**完全正確*/

17   return 0;

18 } /*gdb 除錯發現錯誤出現在這一行*/

至於這個問題的原因,等我有空了進一步考證一下。

這個例子告訴我們段錯誤有可能滯後發生,所以寫**時一定要小心。。。。。

** (

在main前後呼叫函式的方法

方法一 使用 attribute巨集 可宣告多個constructor,在main前呼叫多個函式 attribute constructor void before main attribute destructor void after main intmain int argc,char ar ...

Linux中main函式引數詳解

常用引數有argc和ar 其中ar 是程式後面的字串,argc是第幾個字串。man argc得出 argc the number of arguments to tclsh or wish.ar tcl list of arguments to tclsh or wish.opt getopt ar...

C語言 設定在main 之前執行的函式

include void before attribute constructor void after attribute destructor void before void after int main int argc,char argv 指定了函式在main之前或之後執行。當然也可以指派...