Sender: crough45 AT amc DOT de Message-Id: <97Aug21.092223gmt+0100.17025@internet01.amc.de> Date: Thu, 21 Aug 1997 08:26:55 +0100 From: Chris Croughton Mime-Version: 1.0 To: billc AT blackmagic DOT tait DOT co DOT nz Cc: fesenko AT pacific DOT net DOT sg, djgpp AT delorie DOT com Subject: Re: [Q] wrapping functions with linker Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Precedence: bulk Bill Currie writes: > That's your problem: fopen calls malloc which (for you) calls fopen > which calls malloc... I got tipped off by esp in your stack dump > being so low. Been there, done that - my solution was to explicitly test for recursion, and only do the print if it's not recursing. So in malloc do something like: void* malloc(size_t size) { static bool recurse = false; if (!recurse) { recurse = true; mprintf(...); recurse = false; } /* do alloc stuff... */ } This stops it trying to print while printing. You might also want to provide a sparate function to allocate memory while 'recurse' is set, this can be very simple and reset itself after returning from the print (on the assumption that the C library functions are well-behaved). Chris C