Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!elroy.jpl.nasa.gov!turnkey!orchard.la.locus.com!prodnet.la.locus.com!jfr From: jfr@locus.com (Jon Rosen) Newsgroups: comp.sys.mac.programmer Subject: Re: Pascal deficiency? Message-ID: <20825@oolong.la.locus.com> Date: 21 Dec 90 03:31:48 GMT References: Organization: Locus Computing Corp, Los Angeles Lines: 49 In article aberno@questor.wimsey.bc.ca (Anthony Berno) writes: >I generally prefer Pascal programming, but I have come up against what >seems like a real deficiency in the language. I never really thought >about it before, but there does not seem to be any equivalent to >the ++ or -- operator in Pascal. I was doing some speed checks on >array accessing today, and it occured to me that in doing something >like incrementing an entry by one, the computer was doing rather a >lot of work! > >Either there is no way to do a quick increment in Pascal, or I'm missing >something in my knowledge, or I'm wrong about the speed difference between >things like >++(variable) and >(variable):=(variable)+1 > Your observation is a good one... However, it is not a quality of the language itself that causes the suboptimal performance, but rather the quality of the optimizer... A good Pascal compiler will recognize the construct X := X+1; and perform the appropriate machine code in the best way possible to increment the variable X by 1... Depending on the machine that is being used, this may be a direct register or memory increment instruction or it may end up the same as the assignment statement X := X+2; with a different value being added... In C, X = X+1; and X++; may also be implemented differently depending on the machine or identically... The IBM 370 mainframe, for instance, has no increment/decrement instructions (well, BCTR might be used here, for decrementing) so the C version of these statements is indentical... An example of where a Pascal compiler can be more optimal than a suboptimal C compiler is the WITH statement. Within the domain of a WITH record statement, most good Pascal compilers will attempt to hold a pointer to the record in aworking register... In C compilers, since all structure usages require explicit pointing (struct.field), the compiler that does not do good optimization of the use of a set of structure references might throw constantly reload the register with the pointer to struct... So language makes it easier for compilers to do certain things, but the compiler itself still has to take advantage and the underlying machine architecture has to be able to provide the tools for taking advantage... Otherwise, it really doesn't matter... Jon R.