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



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. 

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.


Regards

David Binderman
 		 	   		  


Home | Main Index | Thread Index | Old Index