Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int main() {
- int b[] = { 33,44,55,66,77,88, };
- int *a = b;
- for (int i = 0; i < 5; ++i) {
- printf("value: %d, address: %p\n", *a, a++);
- }
- return 0;
- }
- $ gcc-9 -Wall -Werror -o sqerror1 sqerror1.c
- sqerror1.c: In function 'main':
- sqerror1.c:10:45: error: operation on 'a' may be undefined [-Werror=sequence-point]
- 10 | printf("value: %d, address: %p\n", *a, a++);
- | ~^~
- cc1: all warnings being treated as errors
- $ clang -Wall -Werror -o sqerror1 sqerror1.c
- sqerror1.c:10:45: error: unsequenced modification and access to 'a' [-Werror,-Wunsequenced]
- printf("value: %d, address: %p\n", *a, a++);
- ~ ^
- 1 error generated.
- # and compiling without -Werror to allow compilation to succeed
- $ clang -Wall -o sqerror1 sqerror1.c
- sqerror1.c:10:45: warning: unsequenced modification and access to 'a' [-Wunsequenced]
- printf("value: %d, address: %p\n", *a, a++);
- ~ ^
- 1 warning generated.
- $ ./sqerror1
- value: 33, address: 0x7ffeedaa9480
- value: 44, address: 0x7ffeedaa9484
- value: 55, address: 0x7ffeedaa9488
- value: 66, address: 0x7ffeedaa948c
- value: 77, address: 0x7ffeedaa9490
- $ gcc-9 -Wall -o sqerror1 sqerror1.c
- sqerror1.c: In function 'main':
- sqerror1.c:10:45: warning: operation on 'a' may be undefined [-Wsequence-point]
- 10 | printf("value: %d, address: %p\n", *a, a++);
- | ~^~
- $ ./sqerror1
- value: 44, address: 0x7ffeeb3e3470
- value: 55, address: 0x7ffeeb3e3474
- value: 66, address: 0x7ffeeb3e3478
- value: 77, address: 0x7ffeeb3e347c
- value: 88, address: 0x7ffeeb3e3480
- Kielder:tmp alansampson$
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement