4 ms·
> No, it mostly affects execution time. That's what I was thinking, too, but most of the time (even if the index is not static) the -1 can be eliminated by jus
by professoretc 6y ago
> No, it mostly affects execution time.
That's what I was thinking, too, but most of the time (even if the index is not static) the -1 can be eliminated by just modifying the address at which the array is assumed to start. That is,
arr[x]
compiles into an access at address
(arr - 1) + x
Since the address of arr is statically known, arr - 1 is, too, and the address of "one before the first element" will be what's written as the base for the memory access.
- adwn 6y ago> Since the address of arr is statically known [...] No, that's almost never the case – only when accessing a static array. Typically, that restricts it to static look-up tables and very simple embedded systems.