assert functions in CC++C#

    技术2022-05-19  24

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

     

    Assert Function                                                                Comments

    assert                                                                                Just work in debug mode;  standard C assert function

    ASSERT                                                                              Just work in debug mode;  MFC assert function

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

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

     

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

     

    System::Diagnostics::Debug::Assert(false, "something wrong");

     

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

     

    #ifdef DEBUG

    System::Diagnostics::Debug::Assert(false, "something wrong");

    #endif


    最新回复(0)