promote.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /* promote.c -- test intergral promotion
  2. This file is part of the LZO real-time data compression library.
  3. Copyright (C) 1996-2015 Markus Franz Xaver Johannes Oberhumer
  4. All Rights Reserved.
  5. The LZO library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU General Public License as
  7. published by the Free Software Foundation; either version 2 of
  8. the License, or (at your option) any later version.
  9. The LZO library 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. You should have received a copy of the GNU General Public License
  14. along with the LZO library; see the file COPYING.
  15. If not, write to the Free Software Foundation, Inc.,
  16. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  17. Markus F.X.J. Oberhumer
  18. <markus@oberhumer.com>
  19. http://www.oberhumer.com/opensource/lzo/
  20. */
  21. #include <stdio.h>
  22. #if defined(_MSC_VER) && (_MSC_VER+0 >= 1000)
  23. /* disable "unreachable code" warnings */
  24. # pragma warning(disable: 4702)
  25. #endif
  26. int main(int argc, char *argv[])
  27. {
  28. unsigned char c;
  29. int s;
  30. if (argc < 0 && argv == NULL) /* avoid warning about unused args */
  31. return 0;
  32. c = (unsigned char) (1 << (8 * sizeof(char) - 1));
  33. s = 8 * (int) (sizeof(int) - sizeof(char));
  34. printf("Integral promotion: ");
  35. {
  36. const int u = (c << s) > 0;
  37. if (u)
  38. {
  39. printf("Classic C (unsigned-preserving)\n");
  40. printf("%d %d %uU\n", c, s, (unsigned)c << s);
  41. return 1;
  42. }
  43. else
  44. {
  45. printf("ANSI C (value-preserving)\n");
  46. printf("%d %d %d\n", c, s, c << s);
  47. return 0;
  48. }
  49. }
  50. }
  51. /* vim:set ts=4 sw=4 et: */