Re: Is this a bug?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Bob Plantz <plantz@xxxxxxxx> writes:

> I have often heard students say they were told that ++x is more
> efficient than x++. From looking at gcc-generated assembly language, I
> knew this is not always true. It's been pointed out here that the
> situation is more "interesting" than I realized.

For an integer type there is no performance difference between ++x and
x++.

For a C++ class which defines operator++ and a copy constructor, there
can be performance differences between ++x and x++.  The latter often
requires the compiler to invoke the copy constructor to hold onto the
old value before invoking operator++.  So if you are writing C++, it's
often a good idea to write ++x when x is a class type, such as an STL
iterator.  The compiler can sometimes eliminate the copy constructor,
but not always.

Ian

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux