Array-syntax vs pointer-syntax and code generation?

  • A+

In the book, "Understand and Using C Pointers" by Richard Reese it says on page 85,

The code generated by vector[i] is different from the code generated by *(vector+i) . The notation vector[i] generates machine code that starts at location vector , moves i positions from this location, and uses its content. The notation *(vector+i) generates machine code that starts at location vector , adds i to the address, and then uses the contents at that address. While the result is the same, the generated machine code is different. This difference is rarely of significance to most programmers.

You can see the exceprt here. What does this passage mean? In what context would any compiler generate different code for those two? Is there a difference between "move" from base, and "add" to base? I was unable to get this to work on GCC -- generating different machine code.


The quote is just wrong. Pretty tragic that such garbage is still published in this decade. In fact the C Standard defines x[y] as *(x+y).

The part about lvalues later on the page is completely and utterly wrong too .

IMHO the best way to use this book is to burn it or otherwise discard it.


:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: