From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15188 invoked by alias); 16 Jul 2009 18:19:59 -0000 Received: (qmail 15170 invoked by uid 22791); 16 Jul 2009 18:19:59 -0000 X-SWARE-Spam-Status: No, hits=-2.5 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from mail3.caviumnetworks.com (HELO mail3.caviumnetworks.com) (12.108.191.235) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 16 Jul 2009 18:19:52 +0000 Received: from caexch01.caveonetworks.com (Not Verified[192.168.16.9]) by mail3.caviumnetworks.com with MailMarshal (v6,2,2,3503) id ; Thu, 16 Jul 2009 14:18:54 -0400 Received: from caexch01.caveonetworks.com ([192.168.16.9]) by caexch01.caveonetworks.com with Microsoft SMTPSVC(6.0.3790.3959); Thu, 16 Jul 2009 11:18:49 -0700 Received: from dd1.caveonetworks.com ([64.169.86.201]) by caexch01.caveonetworks.com over TLS secured channel with Microsoft SMTPSVC(6.0.3790.3959); Thu, 16 Jul 2009 11:18:49 -0700 Message-ID: <4A5F6F09.402@caviumnetworks.com> Date: Thu, 16 Jul 2009 18:19:00 -0000 From: David Daney User-Agent: Thunderbird 2.0.0.21 (X11/20090320) MIME-Version: 1.0 To: Honggang Xu CC: gcc-help@gcc.gnu.org Subject: Re: Is this a bug? References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit 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/msg00267.txt.bz2 Honggang Xu wrote: > Or my understand of keyword "volatile" is wrong, following code outputs > compiled by gcc 4.1.1: x=22 ,y=59 > > main() > { > volatile int x=20,y=35; > x=y++ + x++; > y= ++y + ++x; > printf("x=%d y=%d\n" ,x,y); > > } > Your program has undefined behavior, the volatile may change the output, but it doesn't change the fact that its behavior is undefined. The problem is that the affect of the increment operator can take place either before or after the affect of the assignment. The compiler can order the affects any way that it desires between sequence points. You might want to read up on sequence points: http://en.wikipedia.org/wiki/Sequence_point David Daney