From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 32724 invoked by alias); 17 Jul 2009 00:31:41 -0000 Received: (qmail 32715 invoked by uid 22791); 17 Jul 2009 00:31:40 -0000 X-SWARE-Spam-Status: No, hits=-2.6 required=5.0 tests=AWL,BAYES_00,SPF_PASS X-Spam-Check-By: sourceware.org Received: from smtp-out.google.com (HELO smtp-out.google.com) (216.239.45.13) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 17 Jul 2009 00:31:34 +0000 Received: from zps35.corp.google.com (zps35.corp.google.com [172.25.146.35]) by smtp-out.google.com with ESMTP id n6H0VWRT030261 for ; Thu, 16 Jul 2009 17:31:32 -0700 Received: from wa-out-1112.google.com (wagm34.prod.google.com [10.114.214.34]) by zps35.corp.google.com with ESMTP id n6H0VTVV032739 for ; Thu, 16 Jul 2009 17:31:30 -0700 Received: by wa-out-1112.google.com with SMTP id m34so70630wag.30 for ; Thu, 16 Jul 2009 17:31:29 -0700 (PDT) Received: by 10.115.94.1 with SMTP id w1mr592023wal.71.1247790689702; Thu, 16 Jul 2009 17:31:29 -0700 (PDT) Received: from localhost.localdomain.google.com (adsl-71-133-8-30.dsl.pltn13.pacbell.net [71.133.8.30]) by mx.google.com with ESMTPS id c26sm1018069waa.50.2009.07.16.17.31.28 (version=TLSv1/SSLv3 cipher=RC4-MD5); Thu, 16 Jul 2009 17:31:28 -0700 (PDT) To: Bob Plantz Cc: Honggang Xu , Andrew Haley , David Daney , gcc-help@gcc.gnu.org Subject: Re: Is this a bug? References: <4A5F6F09.402@caviumnetworks.com> <4A5F6FCB.8050804@redhat.com> <1247770653.3567.33.camel@bob-desktop> From: Ian Lance Taylor Date: Fri, 17 Jul 2009 00:31:00 -0000 In-Reply-To: <1247770653.3567.33.camel@bob-desktop> (Bob Plantz's message of "Thu\, 16 Jul 2009 11\:57\:33 -0700") Message-ID: User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-System-Of-Record: true X-IsSubscribed: yes Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org X-SW-Source: 2009-07/txt/msg00276.txt.bz2 Bob Plantz 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