靜態和動態斷言調試,靜態動態斷言調試

來源:互聯網
上載者:User

靜態和動態斷言調試,靜態動態斷言調試

寫程式的時候經常需要調試,下面給出靜態和動態斷言調試以及常用的內建宏。

內建宏:

__FILE__//輸出檔案名

__LINE__//所在行
 __DATE__//日期
 __TIME__//時間
 __FUNCTION__//函數名

static_assert(     constant-expression,     string-literal );
靜態斷言是在編譯時間候用的,因此第一參數的值必須在編譯的時候就能確定,比如長量。如果第二參數為提示資訊。如果第一個參數的運算式值為假則在編譯的時候會出錯,並給出

第二參數值。

void assert(    int expression );
動態斷言在程式運行時候用的,如果運算式的結果為假,則會中斷程式。

#include<iostream>#include<assert.h>using namespace std;void  test(int mouth){assert(mouth>=1&&mouth<=12);//動態斷言cout<<__FILE__<<endl;//輸出檔案名cout<<__LINE__<<endl;//所在行cout<<__DATE__<<endl;//日期cout<<__TIME__<<endl;//時間cout<<__FUNCTION__<<endl;//函數名}int main(){int mouth=12;static_assert(sizeof(void *) == 4, "64-bit code generation is not supported.");//靜態斷言,如果是64 位元系統則不支援test(mouth);cin.get();return 0;}


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.