melder_int.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #ifndef _melder_int_h_
  2. #define _melder_int_h_
  3. /* melder_int.h
  4. *
  5. * Copyright (C) 1992-2018 Paul Boersma
  6. *
  7. * This code is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * This code is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. * See the GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this work. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. /*
  21. * The following two lines are for obsolete (i.e. C99) versions of stdint.h
  22. */
  23. #define __STDC_LIMIT_MACROS
  24. #define __STDC_CONSTANT_MACROS
  25. #include <stdint.h>
  26. using byte = unsigned char;
  27. using int8 = int8_t;
  28. using int16 = int16_t;
  29. using int32 = int32_t;
  30. using int64 = int64_t;
  31. using integer = intptr_t; // the default size of an integer (a "long" is only 32 bits on 64-bit Windows)
  32. using long_not_integer = long; // for cases where we explicitly need the type "long", such as when printfing to %ld
  33. using int_not_integer = int; // for cases where we explicitly need the type "int", such as when scanfing to %n
  34. using uinteger = uintptr_t;
  35. using uint8 = uint8_t;
  36. using uint16 = uint16_t;
  37. using uint32 = uint32_t;
  38. using uint64 = uint64_t;
  39. #ifndef INT12_MAX
  40. #define INT12_MAX 2047
  41. #define INT12_MIN -2048
  42. #endif
  43. #ifndef UINT12_MAX
  44. #define UINT12_MAX 4096
  45. #endif
  46. #ifndef INT24_MAX
  47. #define INT24_MAX 8388607
  48. #define INT24_MIN -8388608
  49. #endif
  50. #ifndef UINT24_MAX
  51. #define UINT24_MAX 16777216
  52. #endif
  53. #define INTEGER_MAX ( sizeof (integer) == 4 ? INT32_MAX : INT64_MAX )
  54. #define INTEGER_MIN ( sizeof (integer) == 4 ? INT32_MIN : INT64_MIN )
  55. /*
  56. The bounds of the contiguous set of integers that in a "double" can represent only themselves.
  57. */
  58. #ifndef INT54_MAX
  59. #define INT54_MAX 9007199254740991LL
  60. #define INT54_MIN -9007199254740991LL
  61. #endif
  62. /*
  63. We assume that the types "integer" and "uinteger" are both large enough to contain
  64. any possible value that Praat wants to assign to them.
  65. This entails that we assume that these types can be converted to each other without bounds checking.
  66. We therefore crash Praat if this second assumption is not met.
  67. */
  68. inline static uinteger integer_to_uinteger (integer n) {
  69. Melder_assert (n >= 0);
  70. return (uinteger) n;
  71. }
  72. inline static integer uinteger_to_integer (uinteger n) {
  73. Melder_assert (n <= INTEGER_MAX);
  74. return (integer) n;
  75. }
  76. /* End of file melder_int.h */
  77. #endif