realloc() (was: Re: Safe coding practices)

Doug Gwyn gwyn at smoke.brl.mil
Sun Feb 24 07:09:37 AEST 1991


In article <6461 at stpstn.UUCP> lerman at stpstn.UUCP (Ken Lerman) writes:
>So the solution is to "#define realloc Realloc" in my code so I can link
>my Realloc with my program.

You should not in general attempt to replace functions normally provided
by the standard C library with your own implementations, because it is
unlikely that you will know precisely what non-obvious constraints the C
library implementation has adopted.  (Often there are subtle things that
need to be taken care of within the C library of which most programmers
are unaware.)  This is especially problematic for memory allocation.  If
you feel the need to provide your own spiffy memory allocation interface,
use your OWN NAMES for those functions and have them call upon the
standard C memory allocation functions as required.  (This could take the
form of one huge allocation at the beginning of an application, which is
subsequently doled out in pieces by your own functions.  Other approaches
are also feasible.)



More information about the Comp.lang.c mailing list