realloc() (was: Re: Safe coding practices)
Walter Bright
bright at nazgul.UUCP
Mon Feb 11 05:06:56 AEST 1991
In article <1991Jan30.204159.5726 at athena.mit.edu> jik at athena.mit.edu (Jonathan I. Kamens) writes:
/If you want to assume that
/because ANSI C specifies realloc() as you quoted, all implementation of
/realloc() you come across specify it in that way, that's your right, but I
/doubt such an assumption is portable
What I do is assume realloc works in an ANSI way across all platforms. If
I discover one in which realloc is broken, the workaround consists of
writing my own replacement in terms of malloc, memcpy, free.
You don't have to suffer the lowest common denominator in library functions.
I also have a set of str... and mem... functions which are written portably,
and are used when I'm stuck on a system that doesn't support them.
Some functions can't be fixed simply, like fork, but a lot can be done if
you are willing to do a minor amount of work.
P.S. I'm not talking about patching the system's libraries or headers, I
insert the replacements in a separate module and link them in, thus overriding
the system libraries.
More information about the Comp.lang.c
mailing list