Hacker News new | ask | show | jobs
by Someone 5299 days ago
A good attempt, but I spot an error:

"They’re not lvalues because both are temporary results of expressions, which don’t have an identifiable memory location (i.e. they can just reside in some temporary register for the duration of the computation)."

The problem is that lvalues _can_ "just reside in some temporary register for the duration of the computation". Any decent optimizing compiler will treat simple loop counters that way.

I am not even sure the C++ standard even mentions registers.

1 comments

Maybe 'register' wasn't abstract enough, he means something like (in psuedo-assembly):

  ldr r1,4     ;Load constant 4 into register 1
  add r2,r2,r1 ;Add contents of r2 and r1, store in r2
  ldr r1,5     ;Load constant 5 into register 1
where the value is only temporarily available for the single calculation. Even without thinking of registers, you can refer to the loop variable, but you can't refer to numbers in your operations.

Maybe he could update this line for clarity, though.