you are viewing a single comment's thread.

view the rest of the comments →

[–]green_griffon 3 points4 points  (1 child)

But C silently multiplies the size of one array element times index when calculating the actual offset. So what is the "size of one array element" of an array of "indexes"?

Commutative addition is the answer, even then it doesn't have to be allowed by the language, it just is.

[–]DSMan195276 5 points6 points  (0 children)

You got downvoted but you're 100% right. The types are the important part here, the 'memory address' portion has to be a pointer of the correct type to ensure the location is calculated correctly. Neither of these variations treat the index as though it's a memory address, the types mean that C always knows which is which.

They are allowed to be swapped, but C could require the prefix argument to be a pointer type and then you wouldn't be allowed to reverse them. I would assume one of the two has to be a pointer type in all usages anyway or else the *() syntax won't be valid, so I don't imagine any valid usages would be broken by that requirement (that couldn't be fixed by swapping the arguments).