Pointer arithmetic and comparisons.

Wm E Davidsen Jr davidsen at crdos1.crd.ge.COM
Tue Dec 12 04:06:16 AEST 1989


In article <232 at bohra.cpg.oz> ejp at 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 at 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



More information about the Comp.lang.c mailing list