Code:
#define for(a) diag("starting loop"); for(a,diag("loop"))

void foo(int i)
{
   for( ; i < 100; i++)
   {
      diag("loop body");
   }
}



on K&R up through latest compilers "for" would expand to

diag("starting loop") for( ; i < 100; i++,diag("loop") {

if __LINE__ and __FILE__ manifest constants were available as well then those could be used to find location. diag is just a quick example in real profiling it would call a short function to also output line, file and time. The log file would be post processes to calculate time spent after average time for output was subtracted.

Additional examples can be found in "C/C++ software quality tools" by Mark L Murphy.

Last edited by Gordon; 09/29/11 14:33.

Our new web site:Westmarch Studios