generic.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /* generic.h: Header file to be included by all other files
  2. Copyright (C) 2002-2004 Sebastian Reichelt
  3. Copyright (C) 2007 Kevin Kofler
  4. This program 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 2, or (at your option)
  7. any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software Foundation,
  14. Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
  15. #ifndef GENERIC_H
  16. #define GENERIC_H
  17. #ifdef __GNUC__
  18. #define ATTRIBUTE_PACKED __attribute__((__packed__))
  19. #define ATTRIBUTE_MAY_ALIAS __attribute__((__may_alias__))
  20. #else
  21. #define ATTRIBUTE_PACKED /**/
  22. #define ATTRIBUTE_MAY_ALIAS /**/
  23. #endif
  24. // Attempt to auto-detect I1, I2, I4, SI1, SI2 and SI4 based on <limits.h>.
  25. // It is a good idea to double-check these definitions on every new system
  26. // you compile on.
  27. // Such a check is also performed at run time (or optimized away as dead
  28. // code).
  29. #include <limits.h>
  30. // Make sure that the character types take exactly 1 byte.
  31. #if UCHAR_MAX != 0xFF
  32. #error Need 1-byte unsigned char type.
  33. #endif /* UCHAR_MAX != 0xFF */
  34. #if SCHAR_MIN != (-0x80) || SCHAR_MAX != 0x7F
  35. #error Need 1-byte signed char type.
  36. #endif /* UCHAR_MAX != 0xFF */
  37. // Unsigned types.
  38. typedef unsigned char I1;
  39. #if USHRT_MAX == 0xFFFF
  40. typedef unsigned short I2;
  41. #elif UINT_MAX == 0xFFFF
  42. typedef unsigned int I2;
  43. #elif ULONG_MAX == 0xFFFF
  44. typedef unsigned long I2;
  45. #else /* no 2-byte unsigned int */
  46. #error No 2-byte unsigned integer type found.
  47. #endif /* 2-byte unsigned int */
  48. #if ULONG_MAX == 0xFFFFFFFF
  49. typedef unsigned long I4;
  50. #elif UINT_MAX == 0xFFFFFFFF
  51. typedef unsigned int I4;
  52. #elif ULONG_LONG_MAX == 0xFFFFFFFF || ULLONG_MAX == 0xFFFFFFFF
  53. typedef unsigned long long I4;
  54. #else /* no 4-byte unsigned int */
  55. #error No 4-byte unsigned integer type found.
  56. #endif /* 4-byte unsigned int */
  57. // Signed types.
  58. typedef signed char SI1;
  59. #if SHRT_MIN == (-0x8000) && SHRT_MAX == 0x7FFF
  60. typedef short SI2;
  61. #elif INT_MIN == (-0x8000) && INT_MAX == 0x7FFF
  62. typedef int SI2;
  63. #elif LONG_MIN == (-0x8000) && LONG_MAX == 0x7FFF
  64. typedef long SI2;
  65. #else /* no 2-byte signed int */
  66. #error No 2-byte signed integer type found.
  67. #endif /* 2-byte signed int */
  68. #if LONG_MIN == (-0x80000000) && LONG_MAX == 0x7FFFFFFF
  69. typedef long SI4;
  70. #elif INT_MIN == (-0x80000000) && INT_MAX == 0x7FFFFFFF
  71. typedef int SI4;
  72. #elif (LONG_LONG_MIN == (-0x80000000) && LONG_LONG_MAX == 0x7FFFFFFF) \
  73. || (LLONG_MIN == (-0x80000000) && LLONG_MAX == 0x7FFFFFFF)
  74. typedef long long SI4;
  75. #else /* no 4-byte signed int */
  76. #error No 4-byte signed integer type found.
  77. #endif /* 4-byte signed int */
  78. // Maximum used specific-size integers.
  79. #define IMAX I4
  80. #define SIMAX SI4
  81. // These should be all right in most cases.
  82. typedef int BOOLEAN;
  83. typedef SI4 COUNT;
  84. typedef COUNT SIZE;
  85. #endif