From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25402 invoked by alias); 3 Jan 2010 11:17:25 -0000 Received: (qmail 25394 invoked by uid 22791); 3 Jan 2010 11:17:24 -0000 X-SWARE-Spam-Status: No, hits=-2.5 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 03 Jan 2010 11:17:20 +0000 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o03BHIsQ015829 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sun, 3 Jan 2010 06:17:18 -0500 Received: from zebedee.pink (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o03BHGHv009972; Sun, 3 Jan 2010 06:17:17 -0500 Message-ID: <4B407CBB.3030109@redhat.com> Date: Sun, 03 Jan 2010 11:17:00 -0000 From: Andrew Haley User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.5) Gecko/20091209 Fedora/3.0-4.fc12 Thunderbird/3.0 MIME-Version: 1.0 To: Andris Kalnozols CC: gcc-help@gcc.gnu.org Subject: Re: gcc-2.95 OK, gcc-{3,4}.X not OK References: <201001030454.UAA02954@nasdaq.hpl.hp.com> In-Reply-To: <201001030454.UAA02954@nasdaq.hpl.hp.com> Content-Type: text/plain; charset=ISO-8859-1 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: 2010-01/txt/msg00014.txt.bz2 On 01/03/2010 04:54 AM, Andris Kalnozols wrote: > Since multiple assignments are legal and evaluated from right to left, > one could expect the following to work: > > pcptr->code = pcptr = nop; I wouldn't. :-) > It does *not* work, however, using the gcc 3.3 or 4.3 compilers. > To summarize: > > pcptr = pcptr->code = nop; /* crashes with no compiler warning */ > pcptr->code = pcptr = nop; /* crashes with the warning: > * operation on `pcptr' may be undefined > */ > pcptr->code = (pcptr = nop); /* same as above */ > pcptr = nop; pcptr->code = nop; /* this works */ > > FWIW, the HP-UX 11.31 compiler warns/not warns in the same > way but the compiled program is "luckier" at run time. > > Perhaps the compiler should regard the above bootstrapping-style > multiple assignments as ambiguous and issue the warning regardless > of the order in which the targets appear. Well, gcc doesn't necessarily know. We do a fair bit of analysis in an attempt to help the programmer, and we warn when we reasonably can, but gcc isn't omniscient. In this case, though, you were burnt by a pointlessly obscure coding style, combined with a misunderstanding of the language. If you write the above code as pcptr = nop; pcptr->code = nop; it'll always work, and its semantics are obvious. Andrew.