> Erik Dalén wrote:
> > On second thought I think you are correct. At the end of the function
> > the pointer might be one byte past the buffer size, but then it won't
> > do any reads or writes (But it could be a problem if the buffer is
> > right at the end of the virtual memory space :).
> 
> The C standard requires that pointer arithmetic work properly
> for one-past-the-end pointers.  On some architectures that may
> mean that each data segment has to have an extra (unused) byte
> allocated, but on most architectures nothing special has to be
> done.

i think what he's saying is that for machines with unsigned ptr
arithmetic, on a 16-bit machine, ~0 (0xffff) is not a legal address;
on a 32-bit machine ~0 (0xffffff) is not a legal address; &c.  on a
machine with page-based vm, i think this means the highest page 
isn't kosher.  (if signed, the problem is at 0x7f(ff)*.)  this is because
for all addresses a except ~0 a < a+1.  i suppose you could hand
out all but the last 2 bytes of the final page.

i don't think it means you have to allocate an extra byte. there's
no requirement that you may indirect the "one-past the end" address.

- erik

Reply via email to