Write My Own Debug Routine

Discussion in 'C++' started by Immortal Nephi, Feb 20, 2010.

  1. I wrote my own debug routine. I use one function from C Run-Time
    library. I believe that it is to be Microsoft Specification. I don’t
    know if another platform such as Mac OXS, Linux, Unix, and other
    Operating System have the same C Run-Time library.
    I use conditional macro to test if WIN32 or STDOUT is enabled. If
    Mac OSX or Linux do not have C Run-Time library function, then debug
    message is always redirected to the console screen. The console
    screen is ideal if you don’t have debugger built-in with IDE.
    Sometimes, debug message is necessary to be written in my source code
    if I want to include valdation to test the data members such as
    inbound array.
    I use C++ iostream instead of printf() function. C++ stringstream is
    very flexible.
    Please tell me what you think my own debug routine. Here is my debug
    routine example. I want that debug routine to be portable. What are
    you suggesting?


    #define LSTR( Wide_String ) L ## Wide_String
    #define WSTR( Wide_String ) LSTR( Wide_String )

    #ifdef _DEBUG
    #if defined( _WIN32 ) || defined( _WIN64 )
    #define ASSERT( expr, message )
    \
    if( !expr )
    \

    { \

    \
    std::wostringstream Expression; \
    Expression << message; \
    std::wstring wstr_Expression = Expression.str(); \

    \
    _CrtDbgReportW( \
    _CRT_ASSERT, \
    WSTR( __FILE__ ), \
    __LINE__, \
    NULL, \
    wstr_Expression.c_str() ); \
    }
    \
    #endif // ( _WIN32 ||
    _WIN64 ) \

    \
    #elif
    defined( STDOUT ) \
    #define ASSERT( expr, message )
    \
    if( !expr )
    \

    { \
    std::wcerr << L"Debug Assertion Failed!\n\n" \
    << L"File: " << __FILE__ << "\n" \
    << L"Line: " << __LINE__ << "\n\n" \
    << L"Expression: " << message << "\n\n" \
    << L"This application has requested the " \
    << L"Runtime to terminate it in an unusual " \
    << L"way.\nPlease contact the application's " \
    << L"support team for more information.\n" << std::endl; \

    \
    std::abort(); \
    } \
    #endif // STDOUT

    \
    #else
    \
    #define ASSERT( expr, message )
    \
    #endif // _DEBUG
    Immortal Nephi, Feb 20, 2010
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Stefan Siegl
    Replies:
    1
    Views:
    769
  2. Edvard Majakari

    Using debug print routine inside assert

    Edvard Majakari, Nov 4, 2003, in forum: Python
    Replies:
    13
    Views:
    598
    Alex Martelli
    Nov 5, 2003
  3. Pflanzen Gold
    Replies:
    11
    Views:
    445
    Moonie
    Aug 12, 2004
  4. Phoe6
    Replies:
    2
    Views:
    435
    Moonie
    Aug 11, 2004
  5. Malcolm McLean

    Portable IEEE754 write routine

    Malcolm McLean, Feb 17, 2010, in forum: C Programming
    Replies:
    7
    Views:
    599
    Ben Pfaff
    Feb 19, 2010
Loading...

Share This Page