C++ compiler questions regarding increment operators -
why considered bad practice use prefix increment operator versus postfix operator old compilers? understanding modern compilers optimize old ones not. there particular reason 1 slower other, , reason left optimized in compiled code? if provide other details regarding operators , compilers i'd grateful, thanks,
by "old" must mean old.
the reason was, in days before real optimization, main system c/unix development pdp-11 , later vax-11. pdp , vax have pre-decrement , post increment addressing modes.
movl r0, -(r1) ; decrements r1 4 , move value of r0 location. movl (r1)+, r2 ; move value @ r1 r2 add 4 r1.
these c equivalent of
*(--a) = b ; b = *(a++) ;
in days of little optimization, these mapped underlying assembly instructions.
at same time these addressing modes did not exist opposite:
movl (r0)-, r1 movl +(r0), r1
therefore, there no hardware mapping
*(++a) = b ; b = *(a--) ;
the -(rx) , (rx)+ addressing modes made easy implement downwards growing stacks.
Comments
Post a Comment