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



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
> main()
> {
>     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.

Joerg



Home | Main Index | Thread Index | Old Index