I
Immortal Nephi
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
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