eles wrote:
> > == Quote from Andrej Mitrovic (andrej.mitrov...@gmail.com)'s article
> > On 5/31/11, eles <e...@eles.com> wrote:
> > > Nice picture, but then why foo[1] is rather 8 than 4? And what is
> foo
> > > [9]?
> > foo[9] is out of range. If foo[1] was actually referring to 4, then
> > foo[0] would be out of range too.  I've only used this picture
> > because
> > back years ago when I was trying to understand how this whole system
> > works there was an explanation similar to this one in some book, the
> > name of which I forgot. But it did 'click' with me when I saw it
> > presented like that.
>
> Yes. Except that if you assume that indexes of an array are
> represented, lets say on an unsigned type UTYPE of n bytes and let's
> note UTYPE_MAX the 2^n-1 value (i.e. the maximum representable value
> on n bytes) and if you have an array of exactly UTYPE_MAX elements:
>
> a[0],...,a[UTYPE_MAX]
> [snip.]

Those are UTYPE_MAX+1 elements. It's natural that you will run into trouble if 
you
cannot even represent the length of your array with your size_t type.

If you have just a[0],...,a[UTYPE_MAX-1], (UTYPE_MAX elements), it will work 
just
fine.

Moreover, it is unlikely that this will happen in 64bit, because your array (of
ints) would take up about 64 Million TB. And you could resolve the issue by
reducing its size by 4 bytes.


Timon

Reply via email to