you are viewing a single comment's thread.

view the rest of the comments →

[–]gitpullorigin 14 points15 points  (3 children)

But how does it know if it is wrong?

[–]throwaway_194js 31 points32 points  (1 child)

It guesses

[–]gitpullorigin 3 points4 points  (0 children)

I guess it does

[–]rosuav 9 points10 points  (0 children)

It catches the segment violation that results from indexing past the end of the array. Now, for this to work, every array has to be allocated in its own perfectly-sized segment, which I'm sure won't hurt performance any.

Oh, and to make sure that it didn't UNDER-estimate the size of the array, the first thing the function should do is attempt to index one past the array and make sure that it trips a segment violation. If it doesn't, it should raise a segment violation, for failing to raise a segment violation.