Are you too lazy to learn your debugger? When debugging, I usually want to know if some code section is reached.
I can do this:
void foobar() {
printf("foobar()\n");
// ... do foobar
}
But I should use
cout
instead printf
in C++ .
printf
is faster, but in this case it should be irrelevant.
So I have:
void foobar() {
std::cout << "foobar()" << std::endl;
// ... do foobar
}
I could also use GCC's function name macro __PRETTY_FUNCTION__
and __LINE__
macro to identify the reached code section easier.
void foobar() {
std::cout << __PRETTY_FUNCTION__ << " at line " << __LINE__ << std::endl;
// ... do foobar
}
Add that on a macro to reuse it:
#if DEBUG
#include
#define REACH std::cout << __PRETTY_FUNCTION__ << " at line " << __LINE__ << std::endl;
#endif
void foobar() {
REACH
// ... do foobar
}
And happy debugging!
Not.