|
Thinking In C++. Volume 2: Practical ProgrammingThus, you must use this technique carefully. The following is a variation on the TRACE(В ) macro: #define D(a) cout << #a "=[" << a << "]" << '\n'; If you want to display an expression, you simply put it inside a call to D(В ). The expression is displayed, followed by its value (assuming there’s an overloaded operator << for the result type). For example, you can say D(a + b). Thus, you can use this macro any time you want to test an intermediate value to make sure things are okay. Of course, these two macros are actually just the two most fundamental things you do with a debugger: trace through the code execution and display values. A good debugger is an excellent productivity tool, but sometimes debuggers are not available, or it’s not convenient to use them. These techniques always work, regardless of the situation. Trace file DISCLAIMER: This section and the next contain code which is officially unsanctioned by the C++ standard. In particular, we redefine cout and new via macros, which can cause surprising results if you’re not careful ...» |
Код для вставки книги в блог HTML
phpBB
текст
|
|