|
From: Erik C. <er...@ar...> - 2003-09-30 08:43:05
|
On Mon, Sep 29, 2003 at 05:33:50PM -0700, Steve G wrote: > >> It doesn't work, unfortunately, because going one past the end > > >> of an array is quite common, eg: > > > >For what it's worth, going one past the end is a special case > >in the C standard and is allowed > > What if the loop increments by 2? Then you are invoking undefined behaviour unless you put a conditional break at the end of the loop to avoid the pointer going out of range. Section 6.3.6 in the ANSI standard. > The pointer can point 100 past the end legally. It's not legal in C. In machine code, of course, only the ABI can rule something illegal and of course the SysV x86 ABI that Linux conforms to doesn't rule stray pointers illegal. If someone wanted to make a skin that checked a program for Boehm-GC-compatibility then it might be an error though. Interesting project. Alternatively you might be able to make a skin that gave more accurate info to the Boehm GC by giving the GC a magic way to find out whether something was an integer or a pointer. > It just can't read or write to memory. :) The one-past-the-end rule applies to creating the pointer, not to using it. You aren't alllowed to use it of course. > Looking at the code in Nicholas's example, the printf part > shouldn't be called...so nothing accessed memory. I guess the > trick must be that the pointers can point to anything...when a > read or write occurs, then you should start the error checking > instead of when doing the math. Yes, I think that's the only sensible way for Annelid to work, -- Erik Corry er...@ar... A: Because it messes up the order in which people normally read text. Q: Why is top-replying such a bad thing? A: Top-replying. Q: What is the most annoying thing in email? |