Earlier quoted context omitted.
This is incorrect; it is undefined behavior according to the spec: http://www.reddit.com/r/programming/comments/1rrefp/a_glimps...
Ok, so do any other compilers handle it differently?
A glimpse of undefined behavior in C
11–20 of 67 posts
Re: A glimpse of undefined behavior in C
#12Not "well-defined" is the proper terminology.
What is the difference? I do not see "well-defined" in the "Terms, definitions, and symbols" part of the standard.
http://en.wikipedia.org/wiki/De_facto
:)
Re: A glimpse of undefined behavior in C
#13Earlier quoted context omitted.
This is incorrect; it is undefined behavior according to the spec: http://www.reddit.com/r/programming/comments/1rrefp/a_glimps...
Ok, so do any other compilers handle it differently?
Classic example: signed integer overflow. It worked for decades. Then one day it didn't.
If you want to know about this particular example: https://news.ycombinator.com/item?id=6824514 (not personally confirmed)
Re: A glimpse of undefined behavior in C
#14Earlier quoted context omitted.
This is incorrect; it is undefined behavior according to the spec: http://www.reddit.com/r/programming/comments/1rrefp/a_glimps...
Ok, so do any other compilers handle it differently?
Clang says:
zsh% clang -o sequencepoints sequencepoints.c
sequencepoints.c:7:18: warning: multiple unsequenced modifications to 'i' [-Wunsequenced]
int r = 1 * a[i++] + 2 * a[i++] + 3 * a[i++];
^ ~~
1 warning generated.
And prints: zsh% ./sequencepoints
140Re: A glimpse of undefined behavior in C
#15I just ran this after compiling it with clang-500.2.79 based on LLVM 3.3svn, and the output was 140. Maybe GCC is to blame?
Re: A glimpse of undefined behavior in C
#16I just ran this after compiling it with clang-500.2.79 based on LLVM 3.3svn, and the output was 140. Maybe GCC is to blame?
Re: A glimpse of undefined behavior in C
#17I just ran this after compiling it with clang-500.2.79 based on LLVM 3.3svn, and the output was 140. Maybe GCC is to blame?
Re: A glimpse of undefined behavior in C
#18Earlier quoted context omitted.
What is the difference? I do not see "well-defined" in the "Terms, definitions, and symbols" part of the standard.
It is 'de facto' defined. http://en.wikipedia.org/wiki/De_facto :)
Re: A glimpse of undefined behavior in C
#19The way I learned that in C a long time ago was "post increment" was "post statement increment".
will give "0 0 1" (gcc 4.2.1), the increment "shouldn't" happen until after the ; if you're going with post statement. I think your rule would expect "0 0 0" with a being 2 after the printf.
BUT! you get a warning, so that's nice.
Re: A glimpse of undefined behavior in C
#20The way I learned that in C a long time ago was "post increment" was "post statement increment".