NetBSD-Bugs archive

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

Re: port-hp300/50852: src/sys/arch/hp300/stand/common/ite.c:239: bad expression



The following reply was made to PR port-hp300/50852; it has been noted by GNATS.

From: Dave Huang <khym%azeotrope.org@localhost>
To: Joerg Sonnenberger <joerg%britannica.bec.de@localhost>
Cc: "gnats-bugs%NetBSD.org@localhost" <gnats-bugs%netbsd.org@localhost>,
	"gnats-admin%netbsd.org@localhost" <gnats-admin%netbsd.org@localhost>,
	"netbsd-bugs%netbsd.org@localhost" <netbsd-bugs%netbsd.org@localhost>
Subject: Re: port-hp300/50852: src/sys/arch/hp300/stand/common/ite.c:239: bad
 expression
Date: Fri, 26 Feb 2016 17:04:46 -0600

 On Fri, Feb 26, 2016 at 09:24:14PM +0100, Joerg Sonnenberger wrote:
 > On Fri, Feb 26, 2016 at 04:45:21PM +0000, David Binderman wrote:
 > > >> Source code is
 > > >>
 > > >> whichconsole = ++whichconsole % (NITE+1);
 > > >>
 > > >> Maybe better code
 > > >>
 > > >> whichconsole = (whichconsole + 1) % (NITE+1);
 > > >
 > > > Independent of the question of which code is better, I don't think the
 > > > error is correct. 
 > > 
 > > False, the error is valid.
 > > 
 > > There are two writes to whichconsole, one on the left of the assignment,
 > > one on the right.
 > > 
 > > The ISO standard doesn't define which order those writes occur.
 > > See Steve Summit's C FAQ for sequence points, section 3.8.
 > 
 > You are wrong. There is no write from the left operand of the
 > assignment. The write is the result of the assignment and as written
 > before is explicitly sequenced by the standard.
 
 How is the code in question different from i = ++i;, which I've always
 been told is undefined? The assignment operator does not introduce a
 sequence point.
 
 gcc thinks it's wrong too:
 
 % cat t.c
 #define NITE 4
 
 int main(void)
 {
   int whichconsole = 0;
   whichconsole = ++whichconsole % (NITE+1);
   return 0;
 }
 
 % cc -Wall t.c
 t.c: In function â??mainâ??:
 t.c:6:16: warning: operation on â??whichconsoleâ?? may be undefined [-Wsequence-point]
    whichconsole = ++whichconsole % (NITE+1);
                 ^
 



Home | Main Index | Thread Index | Old Index