fixed_int.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /* Copyright (C) 2022 Andrius Štikonas
  2. * This file is part of M2-Planet.
  3. *
  4. * M2-Planet is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * M2-Planet is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with M2-Planet. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #include <stdint.h>
  18. struct s
  19. {
  20. uint8_t a;
  21. uint8_t b;
  22. uint16_t c;
  23. uint32_t d;
  24. };
  25. int main() {
  26. uint8_t u8a = 200;
  27. uint8_t u8b = 100;
  28. uint8_t u8c = u8a + u8b;
  29. if(u8c - 44) return 1;
  30. uint16_t u16a = 65535;
  31. uint16_t u16b = 400;
  32. uint16_t u16c = u16a + u16b;
  33. if(u16c - 399) return 2;
  34. uint32_t u32a = 2147483647;
  35. uint32_t u32b = 2147483647;
  36. uint32_t u32c = u32a + u32b + 3;
  37. if(u32c - 1) return 3;
  38. struct s t;
  39. t.c = 1;
  40. t.d = 2147483647;
  41. t.b = 3;
  42. t.a = 4;
  43. if(t.a + t.b + t.c + t.d - 2147483647 - 1 - 3 - 4) return 4;
  44. u16c = u8c;
  45. if(u16c - 44) return 5;
  46. int16_t i16a = u8a;
  47. if(i16a - 200) return 6;
  48. return 0;
  49. }