[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-core-devel
Subject: Re: Krazy: prefix vs. postfix ++ and -- operators
From: Matthew Dawson <matthew () mjdsystems ! ca>
Date: 2011-01-11 18:09:59
Message-ID: 201101111310.04949.matthew () mjdsystems ! ca
[Download RAW message or body]
On Tuesday 11 January 2011 12:36:49 Artur de Souza wrote:
>
> Quoting Rafa? Mi?ecki <zajec5@gmail.com>:
> > Doesn't compiler optimize than anyway, when possible (like inside
> > for)? I was told that when I tried using post incr. in kernel.
>
> You're right. Most of the compilers take care of that today, so you
> don't have to worry about this anymore.
> Of course you can defend one or another based on code readability and
> coding style, but performance-wise it shouldn't be a problem with
> modern compilers.
>
> Cheers,
>
Compilers can only optimize away this code when then can guarantee that no side \
effects occur. For things like iterators, this can be very hard unless the whole \
iterator is inline and the compiler can verify this. For instance, a simplistic \
iterators post incr.: Iterator operator++(Iterator){
Iterator temp = *this;
++(*this);
return temp;
}
Which incurs the assignment operator.
Of course, for standard types the compiler can optimize this away. For C this means \
the compiler can optimize all post incr. as there is no operator overloading, thus \
why the kernel developers don't care.
Matthew
["signature.asc" (application/pgp-signature)]
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic