32 #ifndef CPL_BASE_H_INCLUDED
33 #define CPL_BASE_H_INCLUDED
47 #ifndef _CRT_SECURE_NO_DEPRECATE
48 #define _CRT_SECURE_NO_DEPRECATE
50 #ifndef _CRT_NONSTDC_NO_DEPRECATE
51 #define _CRT_NONSTDC_NO_DEPRECATE
55 #include "cpl_config.h"
62 #if !defined(SIZEOF_INT) || SIZEOF_INT != 4
63 #error "Unexpected value for SIZEOF_INT"
66 #if !defined(SIZEOF_UNSIGNED_LONG) || \
67 (SIZEOF_UNSIGNED_LONG != 4 && SIZEOF_UNSIGNED_LONG != 8)
68 #error "Unexpected value for SIZEOF_UNSIGNED_LONG"
71 #if !defined(SIZEOF_VOIDP)
72 #error "Unexpected value for SIZEOF_VOIDP"
85 #if defined(VSI_NEED_LARGEFILE64_SOURCE) && !defined(_LARGEFILE64_SOURCE)
86 #define _LARGEFILE64_SOURCE 1
95 #if defined(HAVE_ICONV)
96 #define CPL_RECODE_ICONV
99 #define CPL_RECODE_STUB
107 #if defined(GDAL_COMPILATION) && defined(__sun__) && \
108 (__STDC_VERSION__ + 0) >= 201112L && (_XOPEN_SOURCE + 0) < 600
112 #define _XOPEN_SOURCE 600
155 #if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
156 #if !(__cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1900))
157 #error Must have C++11 or newer.
159 #if __cplusplus >= 201402L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201402L)
162 #if __cplusplus >= 201703L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L)
170 #if UINT_MAX == 65535
191 #ifndef CPL_GBOOL_DEFINED
193 #define CPL_GBOOL_DEFINED
201 #define CPL_STATIC_CAST(type, expr) static_cast<type>(expr)
202 #define CPL_REINTERPRET_CAST(type, expr) reinterpret_cast<type>(expr)
204 #define CPL_STATIC_CAST(type, expr) ((type)(expr))
205 #define CPL_REINTERPRET_CAST(type, expr) ((type)(expr))
221 #define GINTBIG_MIN (CPL_STATIC_CAST(GIntBig, 0x80000000) << 32)
223 #define GINTBIG_MAX ((CPL_STATIC_CAST(GIntBig, 0x7FFFFFFF) << 32) | 0xFFFFFFFFU)
225 #define GUINTBIG_MAX \
226 ((CPL_STATIC_CAST(GUIntBig, 0xFFFFFFFFU) << 32) | 0xFFFFFFFFU)
229 #define CPL_HAS_GINT64 1
241 #define GINT64_MIN GINTBIG_MIN
243 #define GINT64_MAX GINTBIG_MAX
245 #define GUINT64_MAX GUINTBIG_MAX
251 #elif SIZEOF_VOIDP == 8
259 #ifdef GDAL_COMPILATION
261 typedef uintptr_t GUIntptr_t;
262 #define CPL_IS_ALIGNED(ptr, quant) \
263 ((CPL_REINTERPRET_CAST(GUIntptr_t, CPL_STATIC_CAST(const void *, ptr)) % \
268 #if (defined(__MSVCRT__) && !(defined(__MINGW64__) && __GNUC__ >= 10)) || \
269 (defined(_WIN32) && defined(_MSC_VER))
270 #define CPL_FRMT_GB_WITHOUT_PREFIX "I64"
273 #define CPL_FRMT_GB_WITHOUT_PREFIX "ll"
277 #define CPL_FRMT_GIB "%" CPL_FRMT_GB_WITHOUT_PREFIX "d"
279 #define CPL_FRMT_GUIB "%" CPL_FRMT_GB_WITHOUT_PREFIX "u"
282 #ifdef COMPAT_WITH_ICC_CONVERSION_CHECK
283 #define CPL_INT64_FITS_ON_INT32(x) ((x) >= INT_MIN && (x) <= INT_MAX)
285 #define CPL_INT64_FITS_ON_INT32(x) \
286 (CPL_STATIC_CAST(GIntBig, CPL_STATIC_CAST(int, x)) == (x))
295 #define CPL_C_START \
306 #if defined(_MSC_VER) && !defined(CPL_DISABLE_DLL)
307 #ifdef GDAL_COMPILATION
308 #define CPL_DLL __declspec(dllexport)
314 #if defined(USE_GCC_VISIBILITY_FLAG)
315 #define CPL_DLL __attribute__((visibility("default")))
316 #if !defined(__MINGW32__)
317 #define CPL_INTERNAL __attribute__((visibility("hidden")))
328 #define CPL_UNSTABLE_API CPL_DLL
334 #ifdef CPL_OPTIONAL_APIS
335 #define CPL_ODLL CPL_DLL
342 #if defined(_MSC_VER) && !defined(CPL_DISABLE_STDCALL)
343 #define CPL_STDCALL __stdcall
351 #define FORCE_CDECL __cdecl
359 #if (defined(__GNUC__) && !defined(__NO_INLINE__)) || defined(_MSC_VER)
360 #define HAS_CPL_INLINE 1
361 #define CPL_INLINE __inline
362 #elif defined(__SUNPRO_CC)
363 #define HAS_CPL_INLINE 1
364 #define CPL_INLINE inline
372 #define MIN(a, b) (((a) < (b)) ? (a) : (b))
374 #define MAX(a, b) (((a) > (b)) ? (a) : (b))
379 #define ABS(x) (((x) < 0) ? (-1 * (x)) : (x))
384 #define M_PI 3.14159265358979323846
395 #define CPLIsEqual(x, y) (fabs((x) - (y)) < 0.0000000000001)
404 #if defined(AFL_FRIENDLY) && defined(__GNUC__)
406 static inline int CPL_afl_friendly_memcmp(
const void *ptr1,
const void *ptr2,
408 __attribute__((always_inline));
410 static inline int CPL_afl_friendly_memcmp(
const void *ptr1,
const void *ptr2,
413 const unsigned char *bptr1 = (
const unsigned char *)ptr1;
414 const unsigned char *bptr2 = (
const unsigned char *)ptr2;
417 unsigned char b1 = *(bptr1++);
418 unsigned char b2 = *(bptr2++);
425 static inline int CPL_afl_friendly_strcmp(
const char *ptr1,
const char *ptr2)
426 __attribute__((always_inline));
428 static inline int CPL_afl_friendly_strcmp(
const char *ptr1,
const char *ptr2)
430 const unsigned char *usptr1 = (
const unsigned char *)ptr1;
431 const unsigned char *usptr2 = (
const unsigned char *)ptr2;
434 unsigned char ch1 = *(usptr1++);
435 unsigned char ch2 = *(usptr2++);
436 if (ch1 == 0 || ch1 != ch2)
441 static inline int CPL_afl_friendly_strncmp(
const char *ptr1,
const char *ptr2,
443 __attribute__((always_inline));
445 static inline int CPL_afl_friendly_strncmp(
const char *ptr1,
const char *ptr2,
448 const unsigned char *usptr1 = (
const unsigned char *)ptr1;
449 const unsigned char *usptr2 = (
const unsigned char *)ptr2;
452 unsigned char ch1 = *(usptr1++);
453 unsigned char ch2 = *(usptr2++);
454 if (ch1 == 0 || ch1 != ch2)
460 static inline int CPL_afl_friendly_strcasecmp(
const char *ptr1,
462 __attribute__((always_inline));
464 static inline int CPL_afl_friendly_strcasecmp(
const char *ptr1,
467 const unsigned char *usptr1 = (
const unsigned char *)ptr1;
468 const unsigned char *usptr2 = (
const unsigned char *)ptr2;
471 unsigned char ch1 = *(usptr1++);
472 unsigned char ch2 = *(usptr2++);
473 ch1 = (
unsigned char)toupper(ch1);
474 ch2 = (
unsigned char)toupper(ch2);
475 if (ch1 == 0 || ch1 != ch2)
480 static inline int CPL_afl_friendly_strncasecmp(
const char *ptr1,
481 const char *ptr2,
size_t len)
482 __attribute__((always_inline));
484 static inline int CPL_afl_friendly_strncasecmp(
const char *ptr1,
485 const char *ptr2,
size_t len)
487 const unsigned char *usptr1 = (
const unsigned char *)ptr1;
488 const unsigned char *usptr2 = (
const unsigned char *)ptr2;
491 unsigned char ch1 = *(usptr1++);
492 unsigned char ch2 = *(usptr2++);
493 ch1 = (
unsigned char)toupper(ch1);
494 ch2 = (
unsigned char)toupper(ch2);
495 if (ch1 == 0 || ch1 != ch2)
501 static inline char *CPL_afl_friendly_strstr(
const char *haystack,
503 __attribute__((always_inline));
505 static inline char *CPL_afl_friendly_strstr(
const char *haystack,
508 const char *ptr_haystack = haystack;
511 const char *ptr_haystack2 = ptr_haystack;
512 const char *ptr_needle = needle;
515 char ch1 = *(ptr_haystack2++);
516 char ch2 = *(ptr_needle++);
518 return (
char *)ptr_haystack;
522 if (*ptr_haystack == 0)
530 #define memcmp CPL_afl_friendly_memcmp
531 #define strcmp CPL_afl_friendly_strcmp
532 #define strncmp CPL_afl_friendly_strncmp
533 #define strcasecmp CPL_afl_friendly_strcasecmp
534 #define strncasecmp CPL_afl_friendly_strncasecmp
535 #define strstr CPL_afl_friendly_strstr
540 #define STRCASECMP(a, b) (_stricmp(a, b))
541 #define STRNCASECMP(a, b, n) (_strnicmp(a, b, n))
544 #define STRCASECMP(a, b) (strcasecmp(a, b))
546 #define STRNCASECMP(a, b, n) (strncasecmp(a, b, n))
549 #define EQUALN(a, b, n) (STRNCASECMP(a, b, n) == 0)
551 #define EQUAL(a, b) (STRCASECMP(a, b) == 0)
558 #ifndef STARTS_WITH_CI
560 #define STARTS_WITH(a, b) (strncmp(a, b, strlen(b)) == 0)
562 #define STARTS_WITH_CI(a, b) EQUALN(a, b, strlen(b))
566 #ifndef CPL_THREADLOCAL
567 #define CPL_THREADLOCAL
582 #define CPLIsNan(x) _isnan(x)
583 #define CPLIsInf(x) (!_isnan(x) && !_finite(x))
584 #define CPLIsFinite(x) _finite(x)
585 #elif defined(__GNUC__) && \
586 (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
589 #define CPLIsNan(x) __builtin_isnan(x)
590 #define CPLIsInf(x) __builtin_isinf(x)
591 #define CPLIsFinite(x) __builtin_isfinite(x)
592 #elif defined(__cplusplus) && defined(HAVE_STD_IS_NAN) && HAVE_STD_IS_NAN
600 return std::isnan(f);
603 static inline int CPLIsNan(
double f)
605 return std::isnan(f);
610 return std::isinf(f);
613 static inline int CPLIsInf(
double f)
615 return std::isinf(f);
620 return std::isfinite(f);
625 return std::isfinite(f);
630 #if defined(__cplusplus) && defined(__GNUC__) && defined(__linux) && \
631 !defined(__ANDROID__) && !defined(CPL_SUPRESS_CPLUSPLUS)
641 static inline int CPLIsNan(
double f)
651 static inline int CPLIsInf(
double f)
658 return !__isnanf(f) && !__isinff(f);
663 return !__isnan(f) && !__isinf(f);
667 #define CPLIsNan(x) isnan(x)
668 #if defined(isinf) || defined(__FreeBSD__)
670 #define CPLIsInf(x) isinf(x)
672 #define CPLIsFinite(x) (!isnan(x) && !isinf(x))
673 #elif defined(__sun__)
675 #define CPLIsInf(x) (!finite(x) && !isnan(x))
676 #define CPLIsFinite(x) finite(x)
678 #define CPLIsInf(x) (0)
679 #define CPLIsFinite(x) (!isnan(x))
692 #if defined(WORDS_BIGENDIAN) && !defined(CPL_MSB) && !defined(CPL_LSB)
696 #if !(defined(CPL_LSB) || defined(CPL_MSB))
707 #if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
713 template <
bool b>
struct CPLStaticAssert
717 template <>
struct CPLStaticAssert<true>
719 static void my_function()
726 #define CPL_STATIC_ASSERT(x) CPLStaticAssert<x>::my_function()
727 #define CPL_STATIC_ASSERT_IF_AVAILABLE(x) CPL_STATIC_ASSERT(x)
731 #define CPL_STATIC_ASSERT_IF_AVAILABLE(x)
741 #define CPL_SWAP16(x) \
742 CPL_STATIC_CAST(GUInt16, (CPL_STATIC_CAST(GUInt16, x) << 8) | \
743 (CPL_STATIC_CAST(GUInt16, x) >> 8))
745 #if defined(HAVE_GCC_BSWAP)
747 #define CPL_SWAP32(x) \
748 CPL_STATIC_CAST(GUInt32, __builtin_bswap32(CPL_STATIC_CAST(GUInt32, x)))
750 #define CPL_SWAP64(x) \
751 CPL_STATIC_CAST(GUInt64, __builtin_bswap64(CPL_STATIC_CAST(GUInt64, x)))
752 #elif defined(_MSC_VER)
753 #define CPL_SWAP32(x) \
754 CPL_STATIC_CAST(GUInt32, _byteswap_ulong(CPL_STATIC_CAST(GUInt32, x)))
755 #define CPL_SWAP64(x) \
756 CPL_STATIC_CAST(GUInt64, _byteswap_uint64(CPL_STATIC_CAST(GUInt64, x)))
759 #define CPL_SWAP32(x) \
760 CPL_STATIC_CAST(GUInt32, \
761 ((CPL_STATIC_CAST(GUInt32, x) & 0x000000ffU) << 24) | \
762 ((CPL_STATIC_CAST(GUInt32, x) & 0x0000ff00U) << 8) | \
763 ((CPL_STATIC_CAST(GUInt32, x) & 0x00ff0000U) >> 8) | \
764 ((CPL_STATIC_CAST(GUInt32, x) & 0xff000000U) >> 24))
767 #define CPL_SWAP64(x) \
768 ((CPL_STATIC_CAST(GUInt64, CPL_SWAP32(CPL_STATIC_CAST(GUInt32, x))) \
770 (CPL_STATIC_CAST(GUInt64, \
771 CPL_SWAP32(CPL_STATIC_CAST( \
772 GUInt32, CPL_STATIC_CAST(GUInt64, x) >> 32)))))
777 #define CPL_SWAP16PTR(x) \
782 memcpy(&_n16, _lx, 2); \
783 CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || \
784 sizeof(*(x)) == 2); \
785 _n16 = CPL_SWAP16(_n16); \
786 memcpy(_lx, &_n16, 2); \
790 #define CPL_SWAP32PTR(x) \
795 memcpy(&_n32, _lx, 4); \
796 CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || \
797 sizeof(*(x)) == 4); \
798 _n32 = CPL_SWAP32(_n32); \
799 memcpy(_lx, &_n32, 4); \
803 #define CPL_SWAP64PTR(x) \
808 memcpy(&_n64, _lx, 8); \
809 CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || \
810 sizeof(*(x)) == 8); \
811 _n64 = CPL_SWAP64(_n64); \
812 memcpy(_lx, &_n64, 8); \
816 #define CPL_SWAPDOUBLE(p) CPL_SWAP64PTR(p)
819 #define CPL_MSBWORD16(x) (x)
820 #define CPL_LSBWORD16(x) CPL_SWAP16(x)
821 #define CPL_MSBWORD32(x) (x)
822 #define CPL_LSBWORD32(x) CPL_SWAP32(x)
823 #define CPL_MSBPTR16(x) \
824 CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 2)
825 #define CPL_LSBPTR16(x) CPL_SWAP16PTR(x)
826 #define CPL_MSBPTR32(x) \
827 CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 4)
828 #define CPL_LSBPTR32(x) CPL_SWAP32PTR(x)
829 #define CPL_MSBPTR64(x) \
830 CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 8)
831 #define CPL_LSBPTR64(x) CPL_SWAP64PTR(x)
834 #define CPL_LSBWORD16(x) (x)
836 #define CPL_MSBWORD16(x) CPL_SWAP16(x)
838 #define CPL_LSBWORD32(x) (x)
840 #define CPL_MSBWORD32(x) CPL_SWAP32(x)
843 #define CPL_LSBPTR16(x) \
844 CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 2)
847 #define CPL_MSBPTR16(x) CPL_SWAP16PTR(x)
850 #define CPL_LSBPTR32(x) \
851 CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 4)
854 #define CPL_MSBPTR32(x) CPL_SWAP32PTR(x)
857 #define CPL_LSBPTR64(x) \
858 CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 8)
861 #define CPL_MSBPTR64(x) CPL_SWAP64PTR(x)
867 #define CPL_LSBINT16PTR(x) \
868 ((*CPL_REINTERPRET_CAST(const GByte *, x)) | \
869 (*((CPL_REINTERPRET_CAST(const GByte *, x)) + 1) << 8))
874 #define CPL_LSBINT32PTR(x) \
875 ((*CPL_REINTERPRET_CAST(const GByte *, x)) | \
876 (*((CPL_REINTERPRET_CAST(const GByte *, x)) + 1) << 8) | \
877 (*((CPL_REINTERPRET_CAST(const GByte *, x)) + 2) << 16) | \
878 (*((CPL_REINTERPRET_CAST(const GByte *, x)) + 3) << 24))
881 #define CPL_LSBSINT16PTR(x) CPL_STATIC_CAST(GInt16, CPL_LSBINT16PTR(x))
885 #define CPL_LSBUINT16PTR(x) CPL_STATIC_CAST(GUInt16, CPL_LSBINT16PTR(x))
888 #define CPL_LSBSINT32PTR(x) CPL_STATIC_CAST(GInt32, CPL_LSBINT32PTR(x))
892 #define CPL_LSBUINT32PTR(x) CPL_STATIC_CAST(GUInt32, CPL_LSBINT32PTR(x))
896 #ifndef UNREFERENCED_PARAM
897 #ifdef UNREFERENCED_PARAMETER
898 #define UNREFERENCED_PARAM(param) UNREFERENCED_PARAMETER(param)
900 #define UNREFERENCED_PARAM(param) ((void)param)
914 #ifndef DISABLE_CVSID
915 #if defined(__GNUC__) && __GNUC__ >= 4
916 #define CPL_CVSID(string) \
917 static const char cpl_cvsid[] __attribute__((used)) = string;
919 #define CPL_CVSID(string) \
920 static const char cpl_cvsid[] = string; \
921 static const char *cvsid_aw() \
923 return (cvsid_aw() ? NULL : cpl_cvsid); \
927 #define CPL_CVSID(string)
932 #if defined(__GNUC__) && __GNUC__ >= 4 && !defined(DOXYGEN_SKIP) && \
933 !(defined(__MINGW64__) && __GNUC__ == 4 && __GNUC_MINOR__ == 6)
935 #define CPL_NULL_TERMINATED __attribute__((__sentinel__))
938 #define CPL_NULL_TERMINATED
941 #if defined(__GNUC__) && __GNUC__ >= 3 && !defined(DOXYGEN_SKIP)
943 #define CPL_PRINT_FUNC_FORMAT(format_idx, arg_idx) \
944 __attribute__((__format__(__printf__, format_idx, arg_idx)))
946 #define CPL_SCAN_FUNC_FORMAT(format_idx, arg_idx) \
947 __attribute__((__format__(__scanf__, format_idx, arg_idx)))
950 #define CPL_PRINT_FUNC_FORMAT(format_idx, arg_idx)
952 #define CPL_SCAN_FUNC_FORMAT(format_idx, arg_idx)
955 #if defined(_MSC_VER) && \
956 (defined(GDAL_COMPILATION) || defined(CPL_ENABLE_MSVC_ANNOTATIONS))
960 #define CPL_FORMAT_STRING(arg) _Printf_format_string_ arg
963 #define CPL_SCANF_FORMAT_STRING(arg) _Scanf_format_string_ arg
966 #define CPL_FORMAT_STRING(arg) arg
968 #define CPL_SCANF_FORMAT_STRING(arg) arg
971 #if defined(__GNUC__) && __GNUC__ >= 4 && !defined(DOXYGEN_SKIP)
973 #define CPL_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
976 #define CPL_WARN_UNUSED_RESULT
979 #if defined(__GNUC__) && __GNUC__ >= 4
981 #define CPL_UNUSED __attribute((__unused__))
988 #if defined(__GNUC__) && __GNUC__ >= 3 && !defined(DOXYGEN_SKIP)
991 #define CPL_NO_RETURN __attribute__((noreturn))
995 #define CPL_NO_RETURN
1000 #ifndef __has_attribute
1001 #define __has_attribute(x) 0
1006 #if ((defined(__GNUC__) && \
1007 (__GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 9))) || \
1008 __has_attribute(returns_nonnull)) && \
1009 !defined(DOXYGEN_SKIP) && !defined(__INTEL_COMPILER)
1011 #define CPL_RETURNS_NONNULL __attribute__((returns_nonnull))
1014 #define CPL_RETURNS_NONNULL
1017 #if defined(__GNUC__) && __GNUC__ >= 4 && !defined(DOXYGEN_SKIP)
1019 #define CPL_RESTRICT __restrict__
1022 #define CPL_RESTRICT
1025 #if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
1029 #define CPL_OVERRIDE override
1032 #define CPL_FINAL final
1035 #define CPL_NON_FINAL
1042 #define CPL_DISALLOW_COPY_ASSIGN(ClassName) \
1043 ClassName(const ClassName &) = delete; \
1044 ClassName &operator=(const ClassName &) = delete;
1048 #if !defined(DOXYGEN_SKIP) && !defined(CPL_WARN_DEPRECATED)
1049 #if defined(__has_extension)
1050 #if __has_extension(attribute_deprecated_with_message)
1052 #define CPL_WARN_DEPRECATED(x) __attribute__((deprecated(x)))
1054 #define CPL_WARN_DEPRECATED(x)
1056 #elif defined(__GNUC__)
1057 #define CPL_WARN_DEPRECATED(x) __attribute__((deprecated))
1059 #define CPL_WARN_DEPRECATED(x)
1063 #if !defined(_MSC_VER) && !defined(__APPLE__) && !defined(_FORTIFY_SOURCE)
1065 #if defined(GDAL_COMPILATION) && defined(WARN_STANDARD_PRINTF)
1066 int vsnprintf(
char *str,
size_t size,
const char *fmt, va_list args)
1067 CPL_WARN_DEPRECATED(
"Use CPLvsnprintf() instead");
1068 int snprintf(
char *str,
size_t size,
const char *fmt, ...)
1073 #elif defined(GDAL_COMPILATION) && !defined(DONT_DEPRECATE_SPRINTF)
1075 CPL_WARN_DEPRECATED("Use snprintf() or
CPLsnprintf() instead");
1080 #if defined(__cplusplus)
1083 #define CPL_ARRAYSIZE(array) \
1084 ((sizeof(array) / sizeof(*(array))) / \
1085 static_cast<size_t>(!(sizeof(array) % sizeof(*(array)))))
1088 #define CPL_ARRAYSIZE(array) (sizeof(array) / sizeof(array[0]))
1093 template <
class T>
static void CPL_IGNORE_RET_VAL(
const T &)
1097 inline static bool CPL_TO_BOOL(
int x)
1105 #if (((__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) || \
1106 (defined(__clang__) && __clang_major__ >= 3)) && \
1108 #define HAVE_GCC_DIAGNOSTIC_PUSH
1111 #if ((__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2)) && \
1113 #define HAVE_GCC_SYSTEM_HEADER
1126 #if __clang_major__ >= 4 || (__clang_major__ == 3 && __clang_minor__ >= 8)
1127 #define CPL_NOSANITIZE_UNSIGNED_INT_OVERFLOW \
1128 __attribute__((no_sanitize("unsigned-integer-overflow")))
1130 #define CPL_NOSANITIZE_UNSIGNED_INT_OVERFLOW
1133 #if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS) && \
1134 defined(GDAL_COMPILATION)
1137 template <
class C,
class A,
class B>
1138 CPL_NOSANITIZE_UNSIGNED_INT_OVERFLOW
inline C CPLUnsanitizedAdd(A a, B b)
1145 #if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
1146 #define CPL_NULLPTR nullptr
1148 #define CPL_NULLPTR NULL
1151 #if defined(__cplusplus) && defined(GDAL_COMPILATION)
1160 template <
typename T>
inline T fits_on(T t)
1175 #if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS) && \
1176 !defined(DOXYGEN_SKIP)
int GPtrDiff_t
Integer type large enough to hold the difference between 2 addresses.
Definition: cpl_port.h:256
#define CPLIsInf(x)
Return whether a floating-pointer number is +/- infinity.
Definition: cpl_port.h:670
unsigned long long GUIntBig
Large unsigned integer type (generally 64-bit unsigned integer type).
Definition: cpl_port.h:218
short GInt16
Int16 type.
Definition: cpl_port.h:181
#define CPL_C_END
Macro to end a block of C symbols.
Definition: cpl_port.h:299
#define CPL_C_START
Macro to start a block of C symbols.
Definition: cpl_port.h:295
GIntBig GInt64
Signed 64 bit integer type.
Definition: cpl_port.h:236
int GBool
Type for boolean values (alias to int)
Definition: cpl_port.h:196
unsigned int GUInt32
Unsigned int32 type.
Definition: cpl_port.h:177
#define CPL_PRINT_FUNC_FORMAT(format_idx, arg_idx)
Tag a function to have printf() formatting.
Definition: cpl_port.h:950
#define CPLIsNan(x)
Return whether a floating-pointer number is NaN.
Definition: cpl_port.h:667
char ** CSLConstList
Type of a constant null-terminated list of nul terminated strings.
Definition: cpl_port.h:1183
GUIntBig GUInt64
Unsigned 64 bit integer type.
Definition: cpl_port.h:238
unsigned short GUInt16
Unsigned int16 type.
Definition: cpl_port.h:183
unsigned char GByte
Unsigned byte type.
Definition: cpl_port.h:185
int GInt32
Int32 type.
Definition: cpl_port.h:175
signed char GInt8
Signed int8 type.
Definition: cpl_port.h:187
long long GIntBig
Large signed integer type (generally 64-bit integer type).
Definition: cpl_port.h:215
#define CPLIsFinite(x)
Return whether a floating-pointer number is finite.
Definition: cpl_port.h:672
int CPLsnprintf(char *str, size_t size, const char *fmt,...)
snprintf() wrapper that is not sensitive to LC_NUMERIC settings.
Definition: cpl_string.cpp:1366