Re:The Descent to C (2013)
by lifthrasiir on Friday September 03, 2021 @12:28PM
(#28406285)
If array were, say, uint32_t* then what `*(array + i)` would do is actually `(intptr_t)array + i * 4` and not `(intptr_t)array + i`. If array were uint16_t* then it's `(intptr_t)array + i * 2`. In short the way the pointer arithmetic gets translated greatly depends on the type of the pointee and thus is not as primitive as it can be.
[ Parent
| on HN ]
I think it depends on the coder if it makes more sense to them to write out the scale by element size or not. For me, the `+` is just pointer arithmetic and of course an addition in number of elements (so I don't think of the scaling at all).
Just saying that "actually it's just array + i" makes more sense - for me(!).