digital adj. Having digits.     peer n. A comrade; a companion; a fellow; an associate. inmotion    
   
Recent Articles
Stop DNSMasq From Forwarding Local Hostnames
Saturday, September 25, 2010
Securing your Wireless LAN
Wednesday, August 18, 2010
Some tips and things you might not know about your wireless network.
Using Different Subversion Client Versions
Wednesday, August 18, 2010
Handling a Subversion Repository URL Change
Sunday, May 3, 2009
If your repository URL changes, you can use the following command to fix existing snapshots.
vfat Mounts Default to Lowercase Shortnames
Tuesday, April 21, 2009
I want a "this is brain-damage" quote from Linus for this mess.
VirtualBox or VMWare Virtual Machine at Login
Sunday, April 12, 2009
How to start a virtual machine in X when a user logs in.
Dialog Progress Bar Through Pipe
Sunday, April 12, 2009
How to use dialog to display a script progress bar and communicate progress to it through a named pipe.
Mount JFFS2 Image
Saturday, October 25, 2008
Example of how to mount a JFFS2 image using mtdblock.

See, you not only have to be a good coder to create a system like Linux, you have to be a sneaky bastard, too.
- Linus Torvalds

Projects-Development...-Wrapping...

Wrapping C/C++ Function Definitions

Sunday, August 20, 2006 by digitalpeer

The following example shows how to wrap function definitions so code can be added to the beginning or end of every function call from one place. The example just counts the number of times the function is called, which is useful for printing a runtime call tree. It can be expanded to time functions calls and generate runtime profiling information if no other means is available. Of course, I don't condone this type of coding. Consider it a proof of concept.

#include <stdio.h>

/**
 * Define a function.
 * 
 * @param ret Function return value.
 * @param name The name of the function.
 * @param params List of parameters with surrounding parenthesis.
 */
#define FUNC(ret, name, params) \
   ret name params \
   { \
      {\
         static unsigned int cnt = 0; \
         printf("%s [%d]\n",__PRETTY_FUNCTION__,cnt++); \
      }

/**
 * End function definition.
 */
#define END }

FUNC(int,myfunc,(int param1,int param2,int param3))
   int x = 0;
   return x++;
END

int main()
{
   myfunc(1,2,3);
   myfunc(1,2,3);
   myfunc(1,2,3);
   return 0;
}

Running the example results in:
 
myfunc [0]
myfunc [1]
myfunc [2]


Submit Comment to This Article - Be the first!
Please post a comment if you have something to add, find something wrong, or would like more information on the topic at hand. Do not use the comment form to contact the author about unrelated concerns!

Name: Email (optional):
Enter verification number here: