Path: utzoo!utgpu!watmath!att!cbnewsl!dfp From: dfp@cbnewsl.ATT.COM (david.f.prosser) Newsgroups: comp.std.c Subject: Re: (char *)(-1) Keywords: pointers, casts Message-ID: <1282@cbnewsl.ATT.COM> Date: 28 Jul 89 12:45:39 GMT References: <2619@yunexus.UUCP> <388@celit.UUCP> <118@psitech.UUCP> <1063@tukki.jyu.fi> Reply-To: dfp@cbnewsl.ATT.COM (david.f.prosser) Organization: AT&T Bell Laboratories Lines: 31 In article <1063@tukki.jyu.fi> tarvaine@tukki.jyu.fi (Tapani Tarvainen) writes: >In article <118@psitech.UUCP> david@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...