93_integer_promotion.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /* integer promotion */
  2. int printf(const char*, ...);
  3. #define promote(s) printf(" %ssigned : %s\n", (s) - 100 < 0 ? " " : "un", #s);
  4. int main (void)
  5. {
  6. struct {
  7. unsigned ub:3;
  8. unsigned u:32;
  9. unsigned long long ullb:35;
  10. unsigned long long ull:64;
  11. unsigned char c;
  12. } s = { 1, 1, 1 };
  13. promote(s.ub);
  14. promote(s.u);
  15. promote(s.ullb);
  16. promote(s.ull);
  17. promote(s.c);
  18. printf("\n");
  19. promote((1 ? s.ub : 1));
  20. promote((1 ? s.u : 1));
  21. promote((1 ? s.ullb : 1));
  22. promote((1 ? s.ull : 1));
  23. promote((1 ? s.c : 1));
  24. printf("\n");
  25. promote(s.ub << 1);
  26. promote(s.u << 1);
  27. promote(s.ullb << 1);
  28. promote(s.ull << 1);
  29. promote(s.c << 1);
  30. printf("\n");
  31. promote(+s.ub);
  32. promote(+s.u);
  33. promote(+s.ullb);
  34. promote(+s.ull);
  35. promote(+s.c);
  36. printf("\n");
  37. promote(-s.ub);
  38. promote(-s.u);
  39. promote(-s.ullb);
  40. promote(-s.ull);
  41. promote(-s.c);
  42. printf("\n");
  43. promote(~s.ub);
  44. promote(~s.u);
  45. promote(~s.ullb);
  46. promote(~s.ull);
  47. promote(~s.c);
  48. printf("\n");
  49. promote(!s.ub);
  50. promote(!s.u);
  51. promote(!s.ullb);
  52. promote(!s.ull);
  53. promote(!s.c);
  54. printf("\n");
  55. promote(+(unsigned)s.ub);
  56. promote(-(unsigned)s.ub);
  57. promote(~(unsigned)s.ub);
  58. promote(!(unsigned)s.ub);
  59. return 0;
  60. }