←back to thread

Indices, not Pointers

(joegm.github.io)
102 points vitalnodo | 1 comments | | HN request time: 0.201s | source
Show context
zahlman ◴[] No.45110423[source]
> There is a pattern I’ve learned while using Zig which I’ve never seen used in any other language.

I've done this in small applications in C (where nodes were already being statically allocated) and/or assembly (hacking on an existing binary).

No idea about the effect on speed in general; I was trying to save a few bytes of storage in a place where that mattered.

replies(5): >>45111351 #>>45111431 #>>45111876 #>>45112740 #>>45112993 #
anonymousiam ◴[] No.45111431[source]
But in C, there's not really any difference between pointers and indices. You can access array elements using either method, and they're both equally efficient.
replies(4): >>45111456 #>>45111634 #>>45112113 #>>45112598 #
1. adrian_b ◴[] No.45112598[source]
After being translated literally in machine language, they are not equally efficient.

However, a C compiler may choose to use in machine language whichever of indices or pointers is more efficient on the target machine, regardless of whether the source program uses indices or pointers.