Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.milw.wisc.edu!cs.utexas.edu!uunet!psitech!david From: david@psitech.UUCP (david Fridley) Newsgroups: comp.std.c Subject: Re: (char *)(-1) Summary: char *sbrk(); Keywords: pointers, casts Message-ID: <120@psitech.UUCP> Date: 31 Jul 89 06:38:36 GMT References: <2619@yunexus.UUCP> <18792@mimsy.UUCP> Organization: PsiTech Inc., Fountain Valley, CA Lines: 35 In article <18792@mimsy.UUCP>, chris@mimsy.UUCP (Chris Torek) writes: > >>... 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? > To quote from the my UNIX System V (Release 3.0) Programmers Reference manual for BRK(2) (page 141): NAME brk,sbrk - change data segment allocation SYNOPSIS int brk (endds) char *endds; char *sbrk (incr) int incr; : : DIAGNOSTICS Upon successful completion, brk returns a value 0 and sbrk returns the old break value. Otherwise, a value of -1 is returned and errno is set to indicate the error. Here we see that sbrk(), a standard UNIX function, which returns a character pointer will return (-1). This is the functioin used by malloc() to get free more free memory from the operation system. -- david. DISCLAIMER: If it's important have a backup. If it ain't broke don't fix it. Proceed at your own risk. My oponions are MY own. Spelling does not count. My fondest dream is to leave this planet.