assert functions in C/C++/C#

来源:互联网 发布:儿童涂色软件 编辑:程序博客网 时间:2024/06/01 08:52

I just had several small tests. Here is a summary to theassertion related APIs we are using in our product.

 

AssertFunction                                                                Comments

assert                                                                                Justwork in debug mode;  standard C assert function

ASSERT                                                                             Justwork in debug mode;  MFC assert function

System::Diagnostics::Debug::Assert                                 Works both indebug mode and Release mode; Managed C++ assert function

System.Diagnostics.Debug.Assert                                     Justwork in debug mode; C# assert function

 

Pleasenote above red line, ‘System::Diagnostics::Debug::Assert’ works both in debugand release mode, so if we have following code in managed C++:

 

System::Diagnostics::Debug::Assert(false, "somethingwrong");

 

Wewould always see the assertion window both in debug and release build. So, inmanaged C++, we’d better use following code to avoid assertion in Prod-build:

 

#ifdefDEBUG

System::Diagnostics::Debug::Assert(false, "somethingwrong");

#endif

原创粉丝点击