[LLVMdev] Is this a bug in clang?

Joe Armstrong joearms at gmail.com
Tue Apr 19 01:59:58 PDT 2011


Is this a bug in clang, or a bug in my thinking?

/Joe Armstrong


When I compile the following program I get different answers in clang and gcc.

  $ gcc bug2.c
  $ ./a.out
  j = 40
  $ clang bug2.c
  $ ./a.out
  j = 41

  I think the correct answer is 41. If my understanding of C is correct
  (which, or course, it might not be) the incremented value of i++ is
  first made available at the next sequence point, which is after the
  ';' at the end of the offending statment statement.


int printf(const char * format, ...);

int main()
  int i, j;
  i = 10;
  j = i++ + 20 + i;
  printf("j = %d\n",j);

More information about the llvm-dev mailing list