Krazy: prefix vs. postfix ++ and -- operators

Matthew Dawson matthew at
Tue Jan 11 18:09:59 GMT 2011

On Tuesday 11 January 2011 12:36:49 Artur de Souza wrote:
> Quoting Rafa? Mi?ecki <zajec5 at>:
> > 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;
	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.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <>

More information about the kde-core-devel mailing list