Comment

Comment by not2b

The reason for leaving integer overflow undefined was not primarily because of one's complement machines. It was for loop optimization.

Consider for (int i = 0; i < ARRAY_WIDTH; i++) out[i] = in[i + offset];

Assuming that i + offset, &out + i, and &in + i + offset do not overflow allows the loop to be cleanly vectorized without checking for wraparound.

The compiler developers in the 80s were trying to come up with rules that didn't require C to be 5x slower than Fortran on scientific applications, and dealing with the consequences of a[i] being equivalent to *(&a + i).

parent not2b 3 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton