alansam

hw060

Jul 8th, 2020
1,073
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $ cat hw060.c
  2.  
  3. #include <stdio.h>
  4.  
  5. int main() {
  6.  
  7.   int val1, val2;
  8.   val2 = 10;
  9.   val1 = ++val2 + ++val2 + ++val2;
  10.  
  11.   printf("%d %d\n", val1, val2);
  12. }
  13.  
  14. $ clang -Wall -std=c11 -o ../../bin/hw060c hw060.c
  15. hw060.c:8:10: warning: multiple unsequenced modifications to 'val2' [-Wunsequenced]
  16.   val1 = ++val2 + ++val2 + ++val2;
  17.          ^        ~~
  18. 1 warning generated.
  19. $ gcc-9 -Wall -std=c11 -o ../../bin/hw060g hw060.c
  20. hw060.c: In function 'main':
  21. hw060.c:8:19: warning: operation on 'val2' may be undefined [-Wsequence-point]
  22.     8 |   val1 = ++val2 + ++val2 + ++val2;
  23.       |                   ^~~~~~
  24. hw060.c:8:19: warning: operation on 'val2' may be undefined [-Wsequence-point]
  25. $ ../../bin/hw060c
  26. 36 13
  27. $ ../../bin/hw060g
  28. 37 13
  29. $
RAW Paste Data