The simplest debug technique is to print out a line contains the required variables value. By printing out a line at a suspect bugs point, it helps for debug . With few magic variables, that ease us debug even more.
They are __FUNCTION__, __PRETTY_FUNCTION__, __LINE__, __FILE__ .
__FUNCTION__ will returns a string of the function name where the print line stay.
__PRETTY_FUNCTION__ will only recognized by gcc compiler, that returns function name with indication the function is from which class.
__FILE__ returns which source code filename.
__LINE__ returns the exact line of the print line.
How to use them? Easy, you just need a printf.
printf("[DEBUG] In %s(), triggers error ...\n",__FUNCTION__);
The same way to print the filename and the line like this:
printf("Errors appear after %s %s\n",__FILE__,__LINE__);
The newer compiler will also recognized __func__ which it is part of C99 standard, it works the same as __FUNCTION__.
Reference: http://gcc.gnu.org/onlinedocs/gcc/Function-Names.html
This is extremely useful
Save a lot work to locate the buggy position.