Back in college one of my teachers used to say one of the most popular use of
macros is to use it to have code sections conditionally compile for debugging
purposes.
I never ended up using this feature since I was very comfortable in the cradles
of gdb
. Visiting C programming after 10 years of not doing any thing serious
in it. Cherry (cherry@) wrote some piece of debuging code which triggered my
memory 10 years back when the teacher was mentioning about using macros to help
debug code.
Here is an extract of the debug function he implemented.
/*
* A debug fucntion to print the content of upm.
*/
static inline void
uvm_physseg_dump_seg(uvm_physseg_t upm)
{
#if defined(DEBUG)
printf("%s: seg->start == %ld\n", __func__,
uvm_physseg_get_start(upm));
printf("%s: seg->end == %ld\n", __func__,
uvm_physseg_get_end(upm));
printf("%s: seg->avail_start == %ld\n", __func__,
uvm_physseg_get_avail_start(upm));
printf("%s: seg->avail_end == %ld\n", __func__,
uvm_physseg_get_avail_end(upm));
printf("====\n\n");
#else
return;
#endif
}
Before this I was inserting random printf()
statements in between the lines
and then removing them, sometime forgetting that I put them in, it was
messy. But these 16 lines of code made things a lot more easier.
I know this post is not a very technical, it is more of a reminider to myself to
do things that make one’s life as a developer easier especially when the code
base grows bigger.