(char *)(-1)

david.f.prosser dfp at cbnewsl.ATT.COM
Fri Jul 28 22:45:39 AEST 1989


In article <1063 at tukki.jyu.fi> tarvaine at tukki.jyu.fi (Tapani Tarvainen) writes:
>In article <118 at psitech.UUCP> david at psitech.UUCP (david Fridley) writes:
>
>>* OUTPUT:
>>* a pointer to the next symbol on the input is returned.  This buffer has
>>* been malloc()ed and should be free()ed when it is nolonger needed. if
>>* NULL is returned there was an error getting the next string, if (-1) is
>>* returned there were no more symbols.
>
>Is it safe to return -1?
>I mean, isn't it possible that (char *)(-1) is a valid pointer
>in some system and could have been returned by malloc(), or does
>the pANS require it isn't?
>
>If -1 isn't safe, is there any other value (besides NULL) that can
>safely be returned from a (any *) function to indicate error?

(char *)-1 could well be a valid pointer returned by malloc().  The
pANS has no guarantee about special pointer values except for the
null pointer.

The "best" way to have other special pointer values is to use the
address of some object (or function) available to both the producer
and consumer.

For example, if there were a function that took as an argument a
pointer to a function and needed two special values (e.g. SIG_DFL
and SIG_IGN), one could use a null pointer for one of the values
and the address of the function in question for the other.

Dave Prosser	...not an official X3J11 answer...



More information about the Comp.std.c mailing list