9 ms·
Are those not equivalent expressions in modern C? I imagine there are more optimal and less optimal ways of actually doing the indexing in machine code and the
by sgtnoodle 6y ago
Are those not equivalent expressions in modern C?
I imagine there are more optimal and less optimal ways of actually doing the indexing in machine code and the former may be better semantics, but I would think a compiler would generate identical machine code for both.
- tinus_hn 6y agoI’m pretty sure you have to take the size of the objects in mind.
- throwaway525142 6y agoNo, these are equivalent. The size of the objects is implicitly taken into account by the compiler, it knows the size of the objects by the type of the pointer.
- amelius 6y ago"Pointer arithmetic" takes care of that. Adding an integer to a pointer will multiply the size of the type pointed to by the integer and adds that to the pointer.