sizes.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /* sizes.c -- print sizes of various types
  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. #if (defined(_WIN32) || defined(_WIN64)) && defined(_MSC_VER)
  22. #ifndef _CRT_NONSTDC_NO_DEPRECATE
  23. #define _CRT_NONSTDC_NO_DEPRECATE 1
  24. #endif
  25. #ifndef _CRT_NONSTDC_NO_WARNINGS
  26. #define _CRT_NONSTDC_NO_WARNINGS 1
  27. #endif
  28. #ifndef _CRT_SECURE_NO_DEPRECATE
  29. #define _CRT_SECURE_NO_DEPRECATE 1
  30. #endif
  31. #ifndef _CRT_SECURE_NO_WARNINGS
  32. #define _CRT_SECURE_NO_WARNINGS 1
  33. #endif
  34. #endif
  35. #include <lzo/lzoconf.h>
  36. #include <stdio.h>
  37. #if (LZO_CC_MSC && (_MSC_VER >= 1300))
  38. /* disable warning C4310: cast truncates constant value */
  39. # pragma warning(disable: 4310)
  40. #endif
  41. union _lzo_align1_t
  42. {
  43. char a_char;
  44. };
  45. struct _lzo_align2_t
  46. {
  47. char a_char;
  48. };
  49. struct _lzo_align3_t
  50. {
  51. char a_char;
  52. long a_long;
  53. };
  54. struct _lzo_align4_t
  55. {
  56. char a_char;
  57. char * a_char_p;
  58. };
  59. struct _lzo_align5_t
  60. {
  61. char a_char1;
  62. long a_long;
  63. char a_char2;
  64. char * a_char_p;
  65. };
  66. union _lzo_align6_t
  67. {
  68. char a_char;
  69. long a_long;
  70. char * a_char_p;
  71. lzo_bytep a_lzobytep;
  72. };
  73. #define print_size(type) \
  74. sprintf(s,"sizeof(%s)",#type); \
  75. printf("%-30s %2ld\n", s, (long)sizeof(type));
  76. #define print_ssize(type,m) \
  77. sprintf(s,"sizeof(%s)",#type); \
  78. printf("%-30s %2ld %20ld\n", s, (long)sizeof(type), (long)(m));
  79. #define print_usize(type,m) \
  80. sprintf(s,"sizeof(%s)",#type); \
  81. printf("%-30s %2ld %20lu\n", s, (long)sizeof(type), (unsigned long)(m));
  82. int main(int argc, char *argv[])
  83. {
  84. char s[80];
  85. print_ssize(char,CHAR_MAX);
  86. print_usize(unsigned char,UCHAR_MAX);
  87. print_ssize(short,SHRT_MAX);
  88. print_usize(unsigned short,USHRT_MAX);
  89. print_ssize(int,INT_MAX);
  90. print_usize(unsigned int,UINT_MAX);
  91. print_ssize(long,LONG_MAX);
  92. print_usize(unsigned long,ULONG_MAX);
  93. printf("\n");
  94. print_size(char *);
  95. print_size(void (*)(void));
  96. printf("\n");
  97. print_ssize(lzo_int,LZO_INT_MAX);
  98. print_usize(lzo_uint,LZO_UINT_MAX);
  99. print_size(lzo_bytep);
  100. printf("\n");
  101. print_size(union _lzo_align1_t);
  102. print_size(struct _lzo_align2_t);
  103. print_size(struct _lzo_align3_t);
  104. print_size(struct _lzo_align4_t);
  105. print_size(struct _lzo_align5_t);
  106. print_size(union _lzo_align6_t);
  107. if (argc < 0 && argv == NULL) /* avoid warning about unused args */
  108. return 0;
  109. return 0;
  110. }
  111. /* vim:set ts=4 sw=4 et: */