Go to the documentation of this file.
32 #ifndef CPL_BASE_H_INCLUDED
33 #define CPL_BASE_H_INCLUDED
45 #if defined(_WIN32) && !defined(WIN32)
49 #if defined(_WINDOWS) && !defined(WIN32)
58 #ifndef _CRT_SECURE_NO_DEPRECATE
59 #define _CRT_SECURE_NO_DEPRECATE
61 #ifndef _CRT_NONSTDC_NO_DEPRECATE
62 #define _CRT_NONSTDC_NO_DEPRECATE
66 #include "cpl_config.h"
73 #if !defined(SIZEOF_INT) || SIZEOF_INT != 4
74 #error "Unexpected value for SIZEOF_INT"
77 #if !defined(SIZEOF_UNSIGNED_LONG) || \
78 (SIZEOF_UNSIGNED_LONG != 4 && SIZEOF_UNSIGNED_LONG != 8)
79 #error "Unexpected value for SIZEOF_UNSIGNED_LONG"
82 #if !defined(SIZEOF_VOIDP)
83 #error "Unexpected value for SIZEOF_VOIDP"
96 #if defined(VSI_NEED_LARGEFILE64_SOURCE) && !defined(_LARGEFILE64_SOURCE)
97 #define _LARGEFILE64_SOURCE 1
106 #if defined(HAVE_ICONV)
107 #define CPL_RECODE_ICONV
110 #define CPL_RECODE_STUB
118 #if defined(GDAL_COMPILATION) && defined(__sun__) && \
119 (__STDC_VERSION__ + 0) >= 201112L && (_XOPEN_SOURCE + 0) < 600
123 #define _XOPEN_SOURCE 600
166 #if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
167 #if !(__cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1900))
168 #error Must have C++11 or newer.
170 #if __cplusplus >= 201402L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201402L)
173 #if __cplusplus >= 201703L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L)
181 #if UINT_MAX == 65535
202 #ifndef CPL_GBOOL_DEFINED
204 #define CPL_GBOOL_DEFINED
212 #define CPL_STATIC_CAST(type, expr) static_cast<type>(expr)
213 #define CPL_REINTERPRET_CAST(type, expr) reinterpret_cast<type>(expr)
215 #define CPL_STATIC_CAST(type, expr) ((type)(expr))
216 #define CPL_REINTERPRET_CAST(type, expr) ((type)(expr))
232 #define GINTBIG_MIN (CPL_STATIC_CAST(GIntBig, 0x80000000) << 32)
234 #define GINTBIG_MAX ((CPL_STATIC_CAST(GIntBig, 0x7FFFFFFF) << 32) | 0xFFFFFFFFU)
236 #define GUINTBIG_MAX \
237 ((CPL_STATIC_CAST(GUIntBig, 0xFFFFFFFFU) << 32) | 0xFFFFFFFFU)
240 #define CPL_HAS_GINT64 1
252 #define GINT64_MIN GINTBIG_MIN
254 #define GINT64_MAX GINTBIG_MAX
256 #define GUINT64_MAX GUINTBIG_MAX
262 #elif SIZEOF_VOIDP == 8
270 #ifdef GDAL_COMPILATION
272 typedef uintptr_t GUIntptr_t;
273 #define CPL_IS_ALIGNED(ptr, quant) \
274 ((CPL_REINTERPRET_CAST(GUIntptr_t, CPL_STATIC_CAST(const void *, ptr)) % \
279 #if (defined(__MSVCRT__) && !(defined(__MINGW64__) && __GNUC__ >= 10)) || \
280 (defined(WIN32) && defined(_MSC_VER))
281 #define CPL_FRMT_GB_WITHOUT_PREFIX "I64"
284 #define CPL_FRMT_GB_WITHOUT_PREFIX "ll"
288 #define CPL_FRMT_GIB "%" CPL_FRMT_GB_WITHOUT_PREFIX "d"
290 #define CPL_FRMT_GUIB "%" CPL_FRMT_GB_WITHOUT_PREFIX "u"
293 #ifdef COMPAT_WITH_ICC_CONVERSION_CHECK
294 #define CPL_INT64_FITS_ON_INT32(x) ((x) >= INT_MIN && (x) <= INT_MAX)
296 #define CPL_INT64_FITS_ON_INT32(x) \
297 (CPL_STATIC_CAST(GIntBig, CPL_STATIC_CAST(int, x)) == (x))
306 #define CPL_C_START \
317 #if defined(_MSC_VER) && !defined(CPL_DISABLE_DLL)
318 #ifdef GDAL_COMPILATION
319 #define CPL_DLL __declspec(dllexport)
325 #if defined(USE_GCC_VISIBILITY_FLAG)
326 #define CPL_DLL __attribute__((visibility("default")))
327 #if !defined(__MINGW32__)
328 #define CPL_INTERNAL __attribute__((visibility("hidden")))
339 #define CPL_UNSTABLE_API CPL_DLL
345 #ifdef CPL_OPTIONAL_APIS
346 #define CPL_ODLL CPL_DLL
353 #if defined(_MSC_VER) && !defined(CPL_DISABLE_STDCALL)
354 #define CPL_STDCALL __stdcall
362 #define FORCE_CDECL __cdecl
370 #if (defined(__GNUC__) && !defined(__NO_INLINE__)) || defined(_MSC_VER)
371 #define HAS_CPL_INLINE 1
372 #define CPL_INLINE __inline
373 #elif defined(__SUNPRO_CC)
374 #define HAS_CPL_INLINE 1
375 #define CPL_INLINE inline
383 #define MIN(a, b) (((a) < (b)) ? (a) : (b))
385 #define MAX(a, b) (((a) > (b)) ? (a) : (b))
390 #define ABS(x) (((x) < 0) ? (-1 * (x)) : (x))
395 #define M_PI 3.14159265358979323846
406 #define CPLIsEqual(x, y) (fabs((x) - (y)) < 0.0000000000001)
415 #if defined(AFL_FRIENDLY) && defined(__GNUC__)
417 static inline int CPL_afl_friendly_memcmp(
const void *ptr1,
const void *ptr2,
419 __attribute__((always_inline));
421 static inline int CPL_afl_friendly_memcmp(
const void *ptr1,
const void *ptr2,
424 const unsigned char *bptr1 = (
const unsigned char *)ptr1;
425 const unsigned char *bptr2 = (
const unsigned char *)ptr2;
428 unsigned char b1 = *(bptr1++);
429 unsigned char b2 = *(bptr2++);
436 static inline int CPL_afl_friendly_strcmp(
const char *ptr1,
const char *ptr2)
437 __attribute__((always_inline));
439 static inline int CPL_afl_friendly_strcmp(
const char *ptr1,
const char *ptr2)
441 const unsigned char *usptr1 = (
const unsigned char *)ptr1;
442 const unsigned char *usptr2 = (
const unsigned char *)ptr2;
445 unsigned char ch1 = *(usptr1++);
446 unsigned char ch2 = *(usptr2++);
447 if (ch1 == 0 || ch1 != ch2)
452 static inline int CPL_afl_friendly_strncmp(
const char *ptr1,
const char *ptr2,
454 __attribute__((always_inline));
456 static inline int CPL_afl_friendly_strncmp(
const char *ptr1,
const char *ptr2,
459 const unsigned char *usptr1 = (
const unsigned char *)ptr1;
460 const unsigned char *usptr2 = (
const unsigned char *)ptr2;
463 unsigned char ch1 = *(usptr1++);
464 unsigned char ch2 = *(usptr2++);
465 if (ch1 == 0 || ch1 != ch2)
471 static inline int CPL_afl_friendly_strcasecmp(
const char *ptr1,
473 __attribute__((always_inline));
475 static inline int CPL_afl_friendly_strcasecmp(
const char *ptr1,
478 const unsigned char *usptr1 = (
const unsigned char *)ptr1;
479 const unsigned char *usptr2 = (
const unsigned char *)ptr2;
482 unsigned char ch1 = *(usptr1++);
483 unsigned char ch2 = *(usptr2++);
484 ch1 = (
unsigned char)toupper(ch1);
485 ch2 = (
unsigned char)toupper(ch2);
486 if (ch1 == 0 || ch1 != ch2)
491 static inline int CPL_afl_friendly_strncasecmp(
const char *ptr1,
492 const char *ptr2,
size_t len)
493 __attribute__((always_inline));
495 static inline int CPL_afl_friendly_strncasecmp(
const char *ptr1,
496 const char *ptr2,
size_t len)
498 const unsigned char *usptr1 = (
const unsigned char *)ptr1;
499 const unsigned char *usptr2 = (
const unsigned char *)ptr2;
502 unsigned char ch1 = *(usptr1++);
503 unsigned char ch2 = *(usptr2++);
504 ch1 = (
unsigned char)toupper(ch1);
505 ch2 = (
unsigned char)toupper(ch2);
506 if (ch1 == 0 || ch1 != ch2)
512 static inline char *CPL_afl_friendly_strstr(
const char *haystack,
514 __attribute__((always_inline));
516 static inline char *CPL_afl_friendly_strstr(
const char *haystack,
519 const char *ptr_haystack = haystack;
522 const char *ptr_haystack2 = ptr_haystack;
523 const char *ptr_needle = needle;
526 char ch1 = *(ptr_haystack2++);
527 char ch2 = *(ptr_needle++);
529 return (
char *)ptr_haystack;
533 if (*ptr_haystack == 0)
541 #define memcmp CPL_afl_friendly_memcmp
542 #define strcmp CPL_afl_friendly_strcmp
543 #define strncmp CPL_afl_friendly_strncmp
544 #define strcasecmp CPL_afl_friendly_strcasecmp
545 #define strncasecmp CPL_afl_friendly_strncasecmp
546 #define strstr CPL_afl_friendly_strstr
551 #define STRCASECMP(a, b) (_stricmp(a, b))
552 #define STRNCASECMP(a, b, n) (_strnicmp(a, b, n))
555 #define STRCASECMP(a, b) (strcasecmp(a, b))
557 #define STRNCASECMP(a, b, n) (strncasecmp(a, b, n))
560 #define EQUALN(a, b, n) (STRNCASECMP(a, b, n) == 0)
562 #define EQUAL(a, b) (STRCASECMP(a, b) == 0)
569 #ifndef STARTS_WITH_CI
571 #define STARTS_WITH(a, b) (strncmp(a, b, strlen(b)) == 0)
573 #define STARTS_WITH_CI(a, b) EQUALN(a, b, strlen(b))
577 #ifndef CPL_THREADLOCAL
578 #define CPL_THREADLOCAL
593 #define CPLIsNan(x) _isnan(x)
594 #define CPLIsInf(x) (!_isnan(x) && !_finite(x))
595 #define CPLIsFinite(x) _finite(x)
596 #elif defined(__GNUC__) && \
597 (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
600 #define CPLIsNan(x) __builtin_isnan(x)
601 #define CPLIsInf(x) __builtin_isinf(x)
602 #define CPLIsFinite(x) __builtin_isfinite(x)
603 #elif defined(__cplusplus) && defined(HAVE_STD_IS_NAN) && HAVE_STD_IS_NAN
611 return std::isnan(f);
613 static inline int CPLIsNan(
double f)
615 return std::isnan(f);
619 return std::isinf(f);
621 static inline int CPLIsInf(
double f)
623 return std::isinf(f);
627 return std::isfinite(f);
631 return std::isfinite(f);
636 #if defined(__cplusplus) && defined(__GNUC__) && defined(__linux) && \
637 !defined(__ANDROID__) && !defined(CPL_SUPRESS_CPLUSPLUS)
646 static inline int CPLIsNan(
double f)
654 static inline int CPLIsInf(
double f)
660 return !__isnanf(f) && !__isinff(f);
664 return !__isnan(f) && !__isinf(f);
668 #define CPLIsNan(x) isnan(x)
669 #if defined(isinf) || defined(__FreeBSD__)
671 #define CPLIsInf(x) isinf(x)
673 #define CPLIsFinite(x) (!isnan(x) && !isinf(x))
674 #elif defined(__sun__)
676 #define CPLIsInf(x) (!finite(x) && !isnan(x))
677 #define CPLIsFinite(x) finite(x)
679 #define CPLIsInf(x) (0)
680 #define CPLIsFinite(x) (!isnan(x))
693 #if defined(WORDS_BIGENDIAN) && !defined(CPL_MSB) && !defined(CPL_LSB)
697 #if !(defined(CPL_LSB) || defined(CPL_MSB))
708 #if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
714 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 // Compatibility with non-clang compilers.
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 &)
1096 inline static bool CPL_TO_BOOL(
int x)
1104 #if (((__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) || \
1105 (defined(__clang__) && __clang_major__ >= 3)) && \
1107 #define HAVE_GCC_DIAGNOSTIC_PUSH
1110 #if ((__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2)) && \
1112 #define HAVE_GCC_SYSTEM_HEADER
1115 #if defined(__has_cpp_attribute)
1116 #if __has_cpp_attribute(fallthrough)
1118 #define CPL_FALLTHROUGH [[fallthrough]];
1120 #elif defined(__clang__) || __GNUC__ >= 7
1122 #define CPL_FALLTHROUGH [[clang::fallthrough]];
1124 #ifndef CPL_FALLTHROUGH
1126 #define CPL_FALLTHROUGH
1139 #if __clang_major__ >= 4 || (__clang_major__ == 3 && __clang_minor__ >= 8)
1140 #define CPL_NOSANITIZE_UNSIGNED_INT_OVERFLOW \
1141 __attribute__((no_sanitize("unsigned-integer-overflow")))
1143 #define CPL_NOSANITIZE_UNSIGNED_INT_OVERFLOW
1146 #if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS) && \
1147 defined(GDAL_COMPILATION)
1150 template <
class C,
class A,
class B>
1151 CPL_NOSANITIZE_UNSIGNED_INT_OVERFLOW
inline C CPLUnsanitizedAdd(A a, B b)
1158 #if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
1159 #define CPL_NULLPTR nullptr
1161 #define CPL_NULLPTR NULL
1170 #if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS) && \
1171 !defined(DOXYGEN_SKIP)
#define CPL_PRINT_FUNC_FORMAT(format_idx, arg_idx)
Tag a function to have printf() formatting.
Definition: cpl_port.h:950
unsigned char GByte
Unsigned byte type.
Definition: cpl_port.h:196
GUIntBig GUInt64
Unsigned 64 bit integer type.
Definition: cpl_port.h:249
short GInt16
Int16 type.
Definition: cpl_port.h:192
int CPLsnprintf(char *str, size_t size, const char *fmt,...)
snprintf() wrapper that is not sensitive to LC_NUMERIC settings.
Definition: cpl_string.cpp:1367
GIntBig GInt64
Signed 64 bit integer type.
Definition: cpl_port.h:247
int GPtrDiff_t
Integer type large enough to hold the difference between 2 addresses.
Definition: cpl_port.h:267
signed char GInt8
Signed int8 type.
Definition: cpl_port.h:198
#define CPL_C_START
Macro to start a block of C symbols.
Definition: cpl_port.h:306
char ** CSLConstList
Type of a constant null-terminated list of nul terminated strings.
Definition: cpl_port.h:1178
unsigned long long GUIntBig
Large unsigned integer type (generally 64-bit unsigned integer type).
Definition: cpl_port.h:229
#define CPLIsNan(x)
Return whether a floating-pointer number is NaN.
Definition: cpl_port.h:668
#define CPL_C_END
Macro to end a block of C symbols.
Definition: cpl_port.h:310
long long GIntBig
Large signed integer type (generally 64-bit integer type).
Definition: cpl_port.h:226
int GBool
Type for boolean values (alias to int)
Definition: cpl_port.h:207
#define CPLIsInf(x)
Return whether a floating-pointer number is +/- infinity.
Definition: cpl_port.h:671
unsigned short GUInt16
Unsigned int16 type.
Definition: cpl_port.h:194
int GInt32
Int32 type.
Definition: cpl_port.h:186
#define CPLIsFinite(x)
Return whether a floating-pointer number is finite.
Definition: cpl_port.h:673
unsigned int GUInt32
Unsigned int32 type.
Definition: cpl_port.h:188