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 (\"All
To fix both the macro-replacement problem, and make LINE etc work as you're hoping they will:
#define malloc(X) my_malloc((X), __FILE__, __LINE__, __FUNCTION__)
void* my_malloc(size_t size, const char *f, int l, const char *u)
{
void *p = (malloc)(size);
printf ("Allocated = %s, %d, %s, %x\n", f, l, u, p);
return p;
}
(That way LINE and friends will be evaluated where the macro is expanded - otherwise they'd always be the same).
Enclosing the name (malloc) in parantheses prevents the macro malloc from being expanded, since it is a function-like macro.