News for hackers. Stuff that matters.
Re:GCC Undefined Behavior Sanitizer – Ubsan by malkia on Thursday October 16, 2014 @07:22PM (#8468483)
I've tried catching this little piece of undefined behaviour, but I was not able to (gcc.4.9 -fsanitize=undefined)

  #include <stdio.h>
  int main() {
    return printf("a") + (printf("b") + printf("c"));
  }
Re:GCC Undefined Behavior Sanitizer – Ubsan by cygx on Thursday October 16, 2014 @07:35PM (#8468536)
What's undefined about that?

The order of evaluation is only unspecified, ie you can't know which permutation of a,b,c you'll get - but you will end up with one of them (as long as IO doesn't fail)...

Re:GCC Undefined Behavior Sanitizer – Ubsan by malkia on Friday October 17, 2014 @11:35AM (#8471472)
Thanks for cygx and readerrrr for correcting me. The difference (to me) of undefined and unspecified is very subtle and often escapes my interpretation when I have to use it later.
Re:GCC Undefined Behavior Sanitizer – Ubsan by readerrrr on Thursday October 16, 2014 @07:32PM (#8468521)
That behavior is unspecified. The result might vary through compilers, but there is no undefined behavior.

If your program can handle the functions being called in a different order you are safe, which is different from u.b. where the compiler can ( theoretically )do anything.

Re:GCC Undefined Behavior Sanitizer – Ubsan by taspeotis on Thursday October 16, 2014 @07:38PM (#8468543)
It's been a long time since I've done C/C++ programming. Is the behaviour undefined because of an overflow (number of characters written + number of characters written + number of characters written might > INT_MAX)?

In the general case, that is. I imagine your program (as written) won't see an integer larger than 3.

Re:GCC Undefined Behavior Sanitizer – Ubsan by readerrrr on Thursday October 16, 2014 @07:46PM (#8468577)
The order of the printf() calls is in question. The order of evaluation is unspecified but not undefined.