From: William Djaja Tjokroaminata Date: 2002-12-03T06:30:22+09:00 Subject: Re: Ruby ++, the one element and generators Daniel Carrera wrote: > True. The whole reason why '++' was invented in C was that it would > reduce the number of CPU instructions: > In C, 'a = a + 1' does this: > 1 -> Store "1" in a memmory location. > + -> Add 1 to 'a' and store the result in another location. > = -> take the contents from this location and put them at the > location of 'a'. > But 'a += 1' does this: > 1 -> Store "1" in a memmory location. > += -> Add it to 'a' and put it directly in the location of 'a', > without the intermediate step. > Whereas 'a++' does this: > ++ -> Increement 'a' by 1 and put the result directly in the > location of 'a'. Without the intermediate location. > Surely, this reason doesn't apply to Ruby. :-) > Daniel. Hmmm..., I don't think the explanation above is strict. I think the current C compilers are free to translate 'a = a + 1' to 'a++'. Because of this, we don't have to worry whether to write 'a = a + 1' or 'a++'. A good C compiler will translate either of these into an assembly/machine equivalent of 'a++'. You can ask/search comp.lang.c if you like. C is one of the languages where a lot of things are not strictly defined. Regards, Bill