Safe coding practices

Doug Gwyn gwyn at smoke.brl.mil
Sat Jan 26 08:28:07 AEST 1991


In article <26081:Jan2520:59:5691 at kramden.acf.nyu.edu> brnstnd at kramden.acf.nyu.edu (Dan Bernstein) writes:
>The relevant point is that if you depend on realloc() either returning 0
>or giving you a pointer to the right amount of memory, your program will
>fail on quite a few machines if it runs out of space. ...
>This is like testing putc() for failure. Sure, the standard insists that
>if putc() returns EOF then there's been an error. But a portable program
>cannot depend on this behavior, because there are just too many machines
>where putchar((char) 255) returns EOF.

Since I haven't run into either of these problems on a wide range of
implementations, I would be inclined to rely on correct operation of
the C implementation and devise work-arounds only when a problem is
encountered.  It is impossible to anticipate all possible errors in
implementing the language.



More information about the Comp.bugs.4bsd.ucb-fixes mailing list