Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!uunet!crdgw1!crdos1!davidsen From: davidsen@crdos1.crd.ge.COM (Wm E Davidsen Jr) Newsgroups: comp.lang.c Subject: Re: Pointer arithmetic and comparisons. Message-ID: <1897@crdos1.crd.ge.COM> Date: 11 Dec 89 17:06:16 GMT References: <257ECDFD.CDD@marob.masa.com> <232@bohra.cpg.oz> Organization: GE Corp R&D Center, Schenectady NY Lines: 16 Reply-exos:@crdgw1:To: davidsen@crdos1.crd.ge.com (bill davidsen) In article <232@bohra.cpg.oz> ejp@bohra.UUCP (Esmond Pitt) writes: | That's because the last element is not &buffer[last] but &buffer[last-1], | and so you should test for <= &buffer[last-1], not < &buffer[last]. | You are incrementing a pointer to point outside the object, and this is | not guaranteed to work under _any_ implementation of C. Your code | should read: There seems no reason why "< &buf[last]" should fail. ANSI C allows you to take the address of the element past the end of the array, although it doesn't require thast you be allowed to dereference it. -- bill davidsen (davidsen@crdos1.crd.GE.COM -or- uunet!crdgw1!crdos1!davidsen) "The world is filled with fools. They blindly follow their so-called 'reason' in the face of the church and common sense. Any fool can see that the world is flat!" - anon