I am trying to override malloc by doing this.
#define malloc(X) my_malloc((X)) void* my_malloc(size_t size) { void *p = malloc(size); printf ("Allocated = %s, %s, %s, %x\n",__FILE__, __LINE__, __FUNCTION__, p); return p; } However, this is indefinitely calling my_malloc recursively (because of malloc call inside my_malloc). I wanted to call C malloc function inside my_malloc and not the macro implementation. Could you please let me know how to do that?
Thanks.
__FILE__,__LINE__and__FUNCTION__(C99 syntax would be__func__) will always expand to the same value according to their placement in the file containingmy_malloc(); you have to put them in your macro definition and pass them tomy_malloc()as arguments!