[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: Joerg Sonnenberger <joerg%britannica.bec.de@localhost>
To: David Binderman <dcb314%hotmail.com@localhost>
Cc: "gnats-bugs%NetBSD.org@localhost" <gnats-bugs%netbsd.org@localhost>,
Subject: Re: port-hp300/50852: src/sys/arch/hp300/stand/common/ite.c:239: bad
Date: Sat, 27 Feb 2016 19:36:09 +0100
On Sat, Feb 27, 2016 at 07:52:56AM +0000, David Binderman wrote:
> Hello there,
> > However, I did see someone say that i = ++i + 1 is well-defined
> > starting in *C++* 11.
> The code in question is C code. Let's leave what happens in C++ aside,
> since it is only muddying the issue.
I never talked about C++. I explicitly talke about C11.
> Let's also leave aside what happens in various C language versions and concentrate
> on the language version the compiler uses for the netBSD code.
> $ more feb27b.c
> #define NITE 4
> Â Â Â int whichconsole = 0;
> Â Â Â whichconsole = ++whichconsole % (NITE+1);
> Â Â Â return 0;
> First, with a recent version of clang, a well known C compiler.
> $ ~/llvm/results/bin/clang -c -g -O2 -Wall -Wextra feb27b.c
> feb27b.c:8:17: warning: multiple unsequenced modifications to 'whichconsole'
> Â Â Â Â Â [-Wunsequenced]
> Â Â Â Â Â Â Â whichconsole = ++whichconsole % (NITE+1);
> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â ~ ^
> 1 warning generated.
> Next a recent version of gcc.
> $ ~/gcc/results/bin/gcc -c -g -O2 -Wall -Wextra feb27b.c
> feb27b.c: In function â??mainâ??:
> feb27b.c:8:15: warning: operation on â??whichconsoleâ?? may be undefined [-Wsequence-point]
> Â whichconsole = ++whichconsole % (NITE+1);
> Â ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
> Two different compilers, in their default language standard, think the code falls
> foul of the C sequence point rules.
> I think it is *much* more likely that the original code is wrong than two separate compilers
> have the same bug in them.
Actually, it is quite likely that the specific warnings for the sequence
point rules just haven't been updated. You keep ignoring the explicit
reference to the standard I gave. It is quite explicit that a sequence
point exists. Ironically, for the pre-increment version, it is highly
likely that no sane compiler ever did not do the correct thing, but
that's beside the point.
Main Index |
Thread Index |