(char *)(-1)
Doug Gwyn
gwyn at smoke.BRL.MIL
Tue Aug 1 03:19:19 AEST 1989
In article <120 at psitech.UUCP> david at psitech.UUCP (david Fridley) writes:
>> >Is it safe to return -1?
>Here we see that sbrk(), a standard UNIX function, which returns a character
>pointer will return (-1).
That doesn't answer the question..
Of course it cannot return -1. Whether it returns (char*)-1 or some
other (char*) that compares equal to -1 when cast to an int has never
been satisfactorily resolved. sbrk()'s behavior is a historical remnant
of the original PDP-11 implementation, when one could get away with this
sloppiness. The SVID deliberately omits sbrk(), because there is no
satisfactory way to specify its return value. I had been urging
migration to returning a null pointer, with applications in the interim
testing both for whatever they're currently testing for and for the new
null pointer value. That way a transition could be made to well-defined
behavior. Instead, the solution seems to have been to ask applications to
limit their access to the heap to malloc()/free(), eschewing brk()/sbrk().
There is certainly no excuse for making this same error in newly designed
interfaces.
More information about the Comp.std.c
mailing list