C 除錯相關

2021-06-19 14:45:29 字數 1560 閱讀 6927

一、編譯時的錯誤捕捉

經典的隱式型別轉換問題:

[cpp]view plain

copy

print?

#include "stdafx.h"

class

;  class

banana  

;  class

orage  

;  orage::orage(const

orage::orage(const

const

banana *pbanana){}  

int_tmain(

intargc, _tchar* argv)    

物件直接賦值給

orage物件,這是不正確的。為了防止這類隱式轉換的問題,加上修飾符即可

expicit在建構函式上,抑制隱式轉換

[cpp]view plain

copy

print?

#include "stdafx.h"

class

;  class

orage  

;  orage::orage(const

int_tmain(

intargc, _tchar* argv)    

這樣在執行的時候,編譯器就會提示錯誤。

那麼如果真要使用=

[cpp]view plain

copy

print?

#include "stdafx.h"

class

;  };  

class

orage  

;  orage::orage(const

int_tmain(

intargc, _tchar* argv)    

關於列舉的:

[cpp]view plain

copy

print?

#include "stdafx.h"

enum

;  enum

;  void

ionlyacceptweektype(

intweektype)  

int_tmain(

intargc, _tchar* argv)    

但是現在接受的卻不是我們想要的型別,所以不建議使用列舉建立整型常量,而是用他們建立新型別:

[cpp]view plain

copy

print?

#include "stdafx.h"

typedef

enum

weektype;  

typedef

enum

monthtype;  

void

ionlyacceptweektype(weektype weektype)  

int_tmain(

intargc, _tchar* argv)  

gdb除錯相關

3.2.1 斷點的工作原理 在本書的所有地方都使用了status breakpoint異常,尤其是在本章中,但卻沒有很明確地解釋這個異常的引發方式。現在,我們就來解釋如何在程序中產生這個異常。在x86指令集中包含了乙個特殊的指令int 3,這個指令將在處理器上產生硬體中斷status breakpo...

(四)除錯相關

使用的除錯方法有debug及打log,目前已知。對於debug,eclipse對應的除錯方法快捷鍵如下 單步 f6 進入 f5 跳出 f7 斷點跳 f8 結束除錯 ctrl f2 log使用的函式 android.util.log常用的方法有以下5個 log.v log.d log.i log.w ...

gdb除錯相關

core檔案用於gdb除錯比較有用 你可以用 ulimit a 看一下core file size 如果是0,可以用ulimit c unlimited 來指定大小不限,或者指定固定的大小 採用automake方式時,要在makefile.am中加入 xx ldflags static libtoo...