Comparison of a bitfield vs a (negative) integer, undefined behavior or compiler bugs?

Viewed 1321

Here is a small program. Should this print 0 or 1, or does it have undefined behavior ?

#include <stdio.h>
struct S0 {
  unsigned f1 : 1;
};

struct S0 s;

int main (void) {
  int x = -3;
  int y = x >= (0, s.f1);
  printf ("%d\n", y);
  return 0;
}

This is taken from a resent CSmith test, and this case is discussed more here .

In particular, GCC, KCC, and CompCert outputs 0, while MSVC 2010, ICC 12.0.2 and recent Clang outputs 1.

3 Answers
Related