[mythtv] C++ style

Joseph A. Caputo jcaputo1 at comcast.net
Wed Feb 11 13:47:50 EST 2004


On Wednesday 11 February 2004 13:25, steve at nexusuk.org wrote:
> On Wed, 11 Feb 2004, John P. Poet wrote:
> > For example, he says to always use pre-decrement/increment instead
> > of post-decrement/increment -- when possible.  The "pre" versions
> > can be converted into more efficient assembly language code, than
> > the "post" versions.  The only time you should use the "post"
> > version, is when you really need the increment/decrement to happend
> > after the *current* value of the variable has been used in the
> > expression.
>
> I would hope the optimizer on the compiler would optimize correctly,
> afterall, it's not hard for the optimizer to spot that you're not
> assigning the value to anything (in which case it doesn't matter if
> you do post or pre, so the optimizer can pick the fastest).

That's only half true.  pre/post inc/decrement is also significant in 
non-assignment expressions, like "if" conditions.  In fact, the only 
time I can think of where it doesn't matter is if it's in it's own 
statement by itself, with no assignment, like:

	foo++;
is equivalent to
	++foo;
or
	for (int i = someval; i < someotherval; i++)
is equivalent to
	for (int i = someval; i < someotherval; ++i)

but
	if (somevar == ++i)
is definitely different than
	if (somevar == i++)


-JAC



More information about the mythtv-dev mailing list