Skip to content

Instantly share code, notes, and snippets.

@yifan-gu
Last active August 29, 2015 13:57
Show Gist options
  • Save yifan-gu/9848440 to your computer and use it in GitHub Desktop.
Save yifan-gu/9848440 to your computer and use it in GitHub Desktop.
test for sequence point
yifan@yifan-laptop:~/c/playground$ cat testsequencepoint.c
#include <stdio.h>
int a[10];
int i;
int main(int argc, char *argv[])
{
for (i = 0; i < 5;) {
a[i] = a[i++] + 5;
}
for (i = 0; i < 5; i++) {
printf("a[%d] = %d\n", i, a[i]);
}
return 0;
}
yifan@yifan-laptop:~/c/playground$ gcc testsequencepoint.c
yifan@yifan-laptop:~/c/playground$ ./a.out
a[0] = 5
a[1] = 5
a[2] = 5
a[3] = 5
a[4] = 5
yifan@yifan-laptop:~/c/playground$ clang testsequencepoint.c
yifan@yifan-laptop:~/c/playground$ ./a.out
a[0] = 0
a[1] = 5
a[2] = 10
a[3] = 15
a[4] = 20
yifan@yifan-laptop:~/c/playground$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment