News for hackers. Stuff that matters.
Re:A semantic model for a substantial fragment of C by danieltillett on Saturday April 01, 2017 @01:09AM (#14010555)
Is this example non-deterministic or just undefined? Sure you should not rely on this code to give you consistent results between compilers and even optimisation levels, but what ever happens should be consistent between runs.
Re:A semantic model for a substantial fragment of C by gravypod on Saturday April 01, 2017 @01:12AM (#14010568)
This is UB and it's caught by both GCC and Clang:

    $ gcc -Wall test.c 
    test.c: In function ‘main’:
    test.c:12:13: warning: operation on ‘a’ may be undefined [-Wsequence-point]
      test(a++, a++);
                ~^~
    $ clang test.c
    test.c:12:8: warning: multiple unsequenced modifications to 'a' [-Wunsequenced]
            test(a++, a++);
                  ^    ~~
    1 warning generated.
Re:A semantic model for a substantial fragment of C by metaobject on Saturday April 01, 2017 @11:53AM (#14012683)
It's interesting that GCC requires -Wall whereas clang issues the warning by default. I wonder how many "bugs" could be caught early if GCC just issued the warning by default as well (for folks who don't religiously use -Wall)?
Re:A semantic model for a substantial fragment of C by Keyframe on Saturday April 01, 2017 @07:46AM (#14011661)
Exactly! Without sequence-point error, output is 1,0 on GCC6, 0,1 with CLang.
Re:A semantic model for a substantial fragment of C by danieltillett on Saturday April 01, 2017 @03:55AM (#14011081)
Exactly. The OP asked for an example of a non- deterministic function not UB.
Re:A semantic model for a substantial fragment of C by fmap on Saturday April 01, 2017 @08:48AM (#14011853)
I'm not sure about non-deterministic behavior without looking it up, but you can fix this example to be implementation defined, rather than undefined like this:

  #include <stdio.h>
  
  int postincrement(int *x) { int y = *x; *x = y + 1; return y; }
  
  int main(int argc, char **argv) {
    int i = 0;
    printf("%d, %d\n", postincrement(&i), postincrement(&i));
    return 0;
  }
The point is that function arguments introduce sequence points, but the specification for i++ is weaker than what you get for a function call. C is full of gotchas like this...
Re:A semantic model for a substantial fragment of C by pasquinelli on Saturday April 01, 2017 @11:16AM (#14012513)
Their term was non-deterministic, but they asked for undefined behavior, because they were asking for examples of course being not fully defined semantically.