code_junkie

signed to unsigned conversion in C - is it always safe?

Nov 10th, 2011
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. unsigned int u = 1234;
  2. int i = -5678;
  3.  
  4. unsigned int result = u + i;
  5.  
  6. #include <stdio.h>
  7.  
  8. int main(void)
  9. {
  10. unsigned int u = 1;
  11. int i = -1;
  12.  
  13. if(u < i)
  14. printf("1 < -1");
  15. else
  16. printf("boring");
  17.  
  18. return 0;
  19. }
  20.  
  21. unsigned int umax = -1; // umax set to UINT_MAX
  22.  
  23. int iValue, iResult;
  24. unsigned int uValue, uResult;
  25.  
  26. unsigned int u = 1234;
  27. int i = -5678;
  28.  
  29. unsigned int result = u + i;
Add Comment
Please, Sign In to add comment