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
120 #if defined(__MINGW32__)
121 #ifndef __MSVCRT_VERSION__
122 #define __MSVCRT_VERSION__ 0x0700
127 #if defined(GDAL_COMPILATION) && defined(__sun__) && \
128 (__STDC_VERSION__ + 0) >= 201112L && (_XOPEN_SOURCE + 0) < 600
132 #define _XOPEN_SOURCE 600
175 #if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
176 #if !(__cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1900))
177 #error Must have C++11 or newer.
179 #if __cplusplus >= 201402L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201402L)
182 #if __cplusplus >= 201703L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L)
190 #if UINT_MAX == 65535
211 #ifndef CPL_GBOOL_DEFINED
213 #define CPL_GBOOL_DEFINED
221 #define CPL_STATIC_CAST(type, expr) static_cast<type>(expr)
222 #define CPL_REINTERPRET_CAST(type, expr) reinterpret_cast<type>(expr)
224 #define CPL_STATIC_CAST(type, expr) ((type)(expr))
225 #define CPL_REINTERPRET_CAST(type, expr) ((type)(expr))
241 #define GINTBIG_MIN (CPL_STATIC_CAST(GIntBig, 0x80000000) << 32)
243 #define GINTBIG_MAX ((CPL_STATIC_CAST(GIntBig, 0x7FFFFFFF) << 32) | 0xFFFFFFFFU)
245 #define GUINTBIG_MAX \
246 ((CPL_STATIC_CAST(GUIntBig, 0xFFFFFFFFU) << 32) | 0xFFFFFFFFU)
249 #define CPL_HAS_GINT64 1
261 #define GINT64_MIN GINTBIG_MIN
263 #define GINT64_MAX GINTBIG_MAX
265 #define GUINT64_MAX GUINTBIG_MAX
271 #elif SIZEOF_VOIDP == 8
279 #ifdef GDAL_COMPILATION
281 typedef uintptr_t GUIntptr_t;
282 #define CPL_IS_ALIGNED(ptr, quant) \
283 ((CPL_REINTERPRET_CAST(GUIntptr_t, CPL_STATIC_CAST(const void *, ptr)) % \
288 #if (defined(__MSVCRT__) && !(defined(__MINGW64__) && __GNUC__ >= 10)) || \
289 (defined(WIN32) && defined(_MSC_VER))
290 #define CPL_FRMT_GB_WITHOUT_PREFIX "I64"
293 #define CPL_FRMT_GB_WITHOUT_PREFIX "ll"
297 #define CPL_FRMT_GIB "%" CPL_FRMT_GB_WITHOUT_PREFIX "d"
299 #define CPL_FRMT_GUIB "%" CPL_FRMT_GB_WITHOUT_PREFIX "u"
302 #ifdef COMPAT_WITH_ICC_CONVERSION_CHECK
303 #define CPL_INT64_FITS_ON_INT32(x) ((x) >= INT_MIN && (x) <= INT_MAX)
305 #define CPL_INT64_FITS_ON_INT32(x) \
306 (CPL_STATIC_CAST(GIntBig, CPL_STATIC_CAST(int, x)) == (x))
315 #define CPL_C_START \
326 #if defined(_MSC_VER) && !defined(CPL_DISABLE_DLL)
327 #ifdef GDAL_COMPILATION
328 #define CPL_DLL __declspec(dllexport)
334 #if defined(USE_GCC_VISIBILITY_FLAG)
335 #define CPL_DLL __attribute__((visibility("default")))
336 #if !defined(__MINGW32__)
337 #define CPL_INTERNAL __attribute__((visibility("hidden")))
348 #define CPL_UNSTABLE_API CPL_DLL
354 #ifdef CPL_OPTIONAL_APIS
355 #define CPL_ODLL CPL_DLL
362 #if defined(_MSC_VER) && !defined(CPL_DISABLE_STDCALL)
363 #define CPL_STDCALL __stdcall
371 #define FORCE_CDECL __cdecl
379 #if (defined(__GNUC__) && !defined(__NO_INLINE__)) || defined(_MSC_VER)
380 #define HAS_CPL_INLINE 1
381 #define CPL_INLINE __inline
382 #elif defined(__SUNPRO_CC)
383 #define HAS_CPL_INLINE 1
384 #define CPL_INLINE inline
392 #define MIN(a, b) (((a) < (b)) ? (a) : (b))
394 #define MAX(a, b) (((a) > (b)) ? (a) : (b))
399 #define ABS(x) (((x) < 0) ? (-1 * (x)) : (x))
404 #define M_PI 3.14159265358979323846
415 #define CPLIsEqual(x, y) (fabs((x) - (y)) < 0.0000000000001)
424 #if defined(AFL_FRIENDLY) && defined(__GNUC__)
426 static inline int CPL_afl_friendly_memcmp(
const void *ptr1,
const void *ptr2,
428 __attribute__((always_inline));
430 static inline int CPL_afl_friendly_memcmp(
const void *ptr1,
const void *ptr2,
433 const unsigned char *bptr1 = (
const unsigned char *)ptr1;
434 const unsigned char *bptr2 = (
const unsigned char *)ptr2;
437 unsigned char b1 = *(bptr1++);
438 unsigned char b2 = *(bptr2++);
445 static inline int CPL_afl_friendly_strcmp(
const char *ptr1,
const char *ptr2)
446 __attribute__((always_inline));
448 static inline int CPL_afl_friendly_strcmp(
const char *ptr1,
const char *ptr2)
450 const unsigned char *usptr1 = (
const unsigned char *)ptr1;
451 const unsigned char *usptr2 = (
const unsigned char *)ptr2;
454 unsigned char ch1 = *(usptr1++);
455 unsigned char ch2 = *(usptr2++);
456 if (ch1 == 0 || ch1 != ch2)
461 static inline int CPL_afl_friendly_strncmp(
const char *ptr1,
const char *ptr2,
463 __attribute__((always_inline));
465 static inline int CPL_afl_friendly_strncmp(
const char *ptr1,
const char *ptr2,
468 const unsigned char *usptr1 = (
const unsigned char *)ptr1;
469 const unsigned char *usptr2 = (
const unsigned char *)ptr2;
472 unsigned char ch1 = *(usptr1++);
473 unsigned char ch2 = *(usptr2++);
474 if (ch1 == 0 || ch1 != ch2)
480 static inline int CPL_afl_friendly_strcasecmp(
const char *ptr1,
482 __attribute__((always_inline));
484 static inline int CPL_afl_friendly_strcasecmp(
const char *ptr1,
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)
500 static inline int CPL_afl_friendly_strncasecmp(
const char *ptr1,
501 const char *ptr2,
size_t len)
502 __attribute__((always_inline));
504 static inline int CPL_afl_friendly_strncasecmp(
const char *ptr1,
505 const char *ptr2,
size_t len)
507 const unsigned char *usptr1 = (
const unsigned char *)ptr1;
508 const unsigned char *usptr2 = (
const unsigned char *)ptr2;
511 unsigned char ch1 = *(usptr1++);
512 unsigned char ch2 = *(usptr2++);
513 ch1 = (
unsigned char)toupper(ch1);
514 ch2 = (
unsigned char)toupper(ch2);
515 if (ch1 == 0 || ch1 != ch2)
521 static inline char *CPL_afl_friendly_strstr(
const char *haystack,
523 __attribute__((always_inline));
525 static inline char *CPL_afl_friendly_strstr(
const char *haystack,
528 const char *ptr_haystack = haystack;
531 const char *ptr_haystack2 = ptr_haystack;
532 const char *ptr_needle = needle;
535 char ch1 = *(ptr_haystack2++);
536 char ch2 = *(ptr_needle++);
538 return (
char *)ptr_haystack;
542 if (*ptr_haystack == 0)
550 #define memcmp CPL_afl_friendly_memcmp
551 #define strcmp CPL_afl_friendly_strcmp
552 #define strncmp CPL_afl_friendly_strncmp
553 #define strcasecmp CPL_afl_friendly_strcasecmp
554 #define strncasecmp CPL_afl_friendly_strncasecmp
555 #define strstr CPL_afl_friendly_strstr
560 #define STRCASECMP(a, b) (_stricmp(a, b))
561 #define STRNCASECMP(a, b, n) (_strnicmp(a, b, n))
564 #define STRCASECMP(a, b) (strcasecmp(a, b))
566 #define STRNCASECMP(a, b, n) (strncasecmp(a, b, n))
569 #define EQUALN(a, b, n) (STRNCASECMP(a, b, n) == 0)
571 #define EQUAL(a, b) (STRCASECMP(a, b) == 0)
578 #ifndef STARTS_WITH_CI
580 #define STARTS_WITH(a, b) (strncmp(a, b, strlen(b)) == 0)
582 #define STARTS_WITH_CI(a, b) EQUALN(a, b, strlen(b))
586 #ifndef CPL_THREADLOCAL
587 #define CPL_THREADLOCAL
602 #define CPLIsNan(x) _isnan(x)
603 #define CPLIsInf(x) (!_isnan(x) && !_finite(x))
604 #define CPLIsFinite(x) _finite(x)
605 #elif defined(__GNUC__) && \
606 (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
609 #define CPLIsNan(x) __builtin_isnan(x)
610 #define CPLIsInf(x) __builtin_isinf(x)
611 #define CPLIsFinite(x) __builtin_isfinite(x)
612 #elif defined(__cplusplus) && defined(HAVE_STD_IS_NAN) && HAVE_STD_IS_NAN
620 return std::isnan(f);
622 static inline int CPLIsNan(
double f)
624 return std::isnan(f);
628 return std::isinf(f);
630 static inline int CPLIsInf(
double f)
632 return std::isinf(f);
636 return std::isfinite(f);
640 return std::isfinite(f);
645 #if defined(__cplusplus) && defined(__GNUC__) && defined(__linux) && \
646 !defined(__ANDROID__) && !defined(CPL_SUPRESS_CPLUSPLUS)
655 static inline int CPLIsNan(
double f)
663 static inline int CPLIsInf(
double f)
669 return !__isnanf(f) && !__isinff(f);
673 return !__isnan(f) && !__isinf(f);
677 #define CPLIsNan(x) isnan(x)
678 #if defined(isinf) || defined(__FreeBSD__)
680 #define CPLIsInf(x) isinf(x)
682 #define CPLIsFinite(x) (!isnan(x) && !isinf(x))
683 #elif defined(__sun__)
685 #define CPLIsInf(x) (!finite(x) && !isnan(x))
686 #define CPLIsFinite(x) finite(x)
688 #define CPLIsInf(x) (0)
689 #define CPLIsFinite(x) (!isnan(x))
702 #if defined(WORDS_BIGENDIAN) && !defined(CPL_MSB) && !defined(CPL_LSB)
706 #if !(defined(CPL_LSB) || defined(CPL_MSB))
717 #if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
723 template <
bool b>
struct CPLStaticAssert
726 template <>
struct CPLStaticAssert<true>
728 static void my_function()
735 #define CPL_STATIC_ASSERT(x) CPLStaticAssert<x>::my_function()
736 #define CPL_STATIC_ASSERT_IF_AVAILABLE(x) CPL_STATIC_ASSERT(x)
740 #define CPL_STATIC_ASSERT_IF_AVAILABLE(x)
750 #define CPL_SWAP16(x) \
751 CPL_STATIC_CAST(GUInt16, (CPL_STATIC_CAST(GUInt16, x) << 8) | \
752 (CPL_STATIC_CAST(GUInt16, x) >> 8))
754 #if defined(HAVE_GCC_BSWAP)
756 #define CPL_SWAP32(x) \
757 CPL_STATIC_CAST(GUInt32, __builtin_bswap32(CPL_STATIC_CAST(GUInt32, x)))
759 #define CPL_SWAP64(x) \
760 CPL_STATIC_CAST(GUInt64, __builtin_bswap64(CPL_STATIC_CAST(GUInt64, x)))
761 #elif defined(_MSC_VER)
762 #define CPL_SWAP32(x) \
763 CPL_STATIC_CAST(GUInt32, _byteswap_ulong(CPL_STATIC_CAST(GUInt32, x)))
764 #define CPL_SWAP64(x) \
765 CPL_STATIC_CAST(GUInt64, _byteswap_uint64(CPL_STATIC_CAST(GUInt64, x)))
768 #define CPL_SWAP32(x) \
769 CPL_STATIC_CAST(GUInt32, \
770 ((CPL_STATIC_CAST(GUInt32, x) & 0x000000ffU) << 24) | \
771 ((CPL_STATIC_CAST(GUInt32, x) & 0x0000ff00U) << 8) | \
772 ((CPL_STATIC_CAST(GUInt32, x) & 0x00ff0000U) >> 8) | \
773 ((CPL_STATIC_CAST(GUInt32, x) & 0xff000000U) >> 24))
776 #define CPL_SWAP64(x) \
777 ((CPL_STATIC_CAST(GUInt64, CPL_SWAP32(CPL_STATIC_CAST(GUInt32, x))) \
779 (CPL_STATIC_CAST(GUInt64, \
780 CPL_SWAP32(CPL_STATIC_CAST( \
781 GUInt32, CPL_STATIC_CAST(GUInt64, x) >> 32)))))
786 #define CPL_SWAP16PTR(x) \
791 memcpy(&_n16, _lx, 2); \
792 CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || \
793 sizeof(*(x)) == 2); \
794 _n16 = CPL_SWAP16(_n16); \
795 memcpy(_lx, &_n16, 2); \
799 #define CPL_SWAP32PTR(x) \
804 memcpy(&_n32, _lx, 4); \
805 CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || \
806 sizeof(*(x)) == 4); \
807 _n32 = CPL_SWAP32(_n32); \
808 memcpy(_lx, &_n32, 4); \
812 #define CPL_SWAP64PTR(x) \
817 memcpy(&_n64, _lx, 8); \
818 CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || \
819 sizeof(*(x)) == 8); \
820 _n64 = CPL_SWAP64(_n64); \
821 memcpy(_lx, &_n64, 8); \
825 #define CPL_SWAPDOUBLE(p) CPL_SWAP64PTR(p)
828 #define CPL_MSBWORD16(x) (x)
829 #define CPL_LSBWORD16(x) CPL_SWAP16(x)
830 #define CPL_MSBWORD32(x) (x)
831 #define CPL_LSBWORD32(x) CPL_SWAP32(x)
832 #define CPL_MSBPTR16(x) \
833 CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 2)
834 #define CPL_LSBPTR16(x) CPL_SWAP16PTR(x)
835 #define CPL_MSBPTR32(x) \
836 CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 4)
837 #define CPL_LSBPTR32(x) CPL_SWAP32PTR(x)
838 #define CPL_MSBPTR64(x) \
839 CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 8)
840 #define CPL_LSBPTR64(x) CPL_SWAP64PTR(x)
843 #define CPL_LSBWORD16(x) (x)
845 #define CPL_MSBWORD16(x) CPL_SWAP16(x)
847 #define CPL_LSBWORD32(x) (x)
849 #define CPL_MSBWORD32(x) CPL_SWAP32(x)
852 #define CPL_LSBPTR16(x) \
853 CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 2)
856 #define CPL_MSBPTR16(x) CPL_SWAP16PTR(x)
859 #define CPL_LSBPTR32(x) \
860 CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 4)
863 #define CPL_MSBPTR32(x) CPL_SWAP32PTR(x)
866 #define CPL_LSBPTR64(x) \
867 CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 8)
870 #define CPL_MSBPTR64(x) CPL_SWAP64PTR(x)
876 #define CPL_LSBINT16PTR(x) \
877 ((*CPL_REINTERPRET_CAST(const GByte *, x)) | \
878 (*((CPL_REINTERPRET_CAST(const GByte *, x)) + 1) << 8))
883 #define CPL_LSBINT32PTR(x) \
884 ((*CPL_REINTERPRET_CAST(const GByte *, x)) | \
885 (*((CPL_REINTERPRET_CAST(const GByte *, x)) + 1) << 8) | \
886 (*((CPL_REINTERPRET_CAST(const GByte *, x)) + 2) << 16) | \
887 (*((CPL_REINTERPRET_CAST(const GByte *, x)) + 3) << 24))
890 #define CPL_LSBSINT16PTR(x) CPL_STATIC_CAST(GInt16, CPL_LSBINT16PTR(x))
894 #define CPL_LSBUINT16PTR(x) CPL_STATIC_CAST(GUInt16, CPL_LSBINT16PTR(x))
897 #define CPL_LSBSINT32PTR(x) CPL_STATIC_CAST(GInt32, CPL_LSBINT32PTR(x))
901 #define CPL_LSBUINT32PTR(x) CPL_STATIC_CAST(GUInt32, CPL_LSBINT32PTR(x))
905 #ifndef UNREFERENCED_PARAM
906 #ifdef UNREFERENCED_PARAMETER
907 #define UNREFERENCED_PARAM(param) UNREFERENCED_PARAMETER(param)
909 #define UNREFERENCED_PARAM(param) ((void)param)
923 #ifndef DISABLE_CVSID
924 #if defined(__GNUC__) && __GNUC__ >= 4
925 #define CPL_CVSID(string) \
926 static const char cpl_cvsid[] __attribute__((used)) = string;
928 #define CPL_CVSID(string) \
929 static const char cpl_cvsid[] = string; \
930 static const char *cvsid_aw() \
932 return (cvsid_aw() ? NULL : cpl_cvsid); \
936 #define CPL_CVSID(string)
941 #if defined(__GNUC__) && __GNUC__ >= 4 && !defined(DOXYGEN_SKIP) && \
942 !(defined(__MINGW64__) && __GNUC__ == 4 && __GNUC_MINOR__ == 6)
944 #define CPL_NULL_TERMINATED __attribute__((__sentinel__))
947 #define CPL_NULL_TERMINATED
950 #if defined(__GNUC__) && __GNUC__ >= 3 && !defined(DOXYGEN_SKIP)
952 #define CPL_PRINT_FUNC_FORMAT(format_idx, arg_idx) \
953 __attribute__((__format__(__printf__, format_idx, arg_idx)))
955 #define CPL_SCAN_FUNC_FORMAT(format_idx, arg_idx) \
956 __attribute__((__format__(__scanf__, format_idx, arg_idx)))
959 #define CPL_PRINT_FUNC_FORMAT(format_idx, arg_idx)
961 #define CPL_SCAN_FUNC_FORMAT(format_idx, arg_idx)
964 #if defined(_MSC_VER) && \
965 (defined(GDAL_COMPILATION) || defined(CPL_ENABLE_MSVC_ANNOTATIONS))
969 #define CPL_FORMAT_STRING(arg) _Printf_format_string_ arg
972 #define CPL_SCANF_FORMAT_STRING(arg) _Scanf_format_string_ arg
975 #define CPL_FORMAT_STRING(arg) arg
977 #define CPL_SCANF_FORMAT_STRING(arg) arg
980 #if defined(__GNUC__) && __GNUC__ >= 4 && !defined(DOXYGEN_SKIP)
982 #define CPL_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
985 #define CPL_WARN_UNUSED_RESULT
988 #if defined(__GNUC__) && __GNUC__ >= 4
990 #define CPL_UNUSED __attribute((__unused__))
997 #if defined(__GNUC__) && __GNUC__ >= 3 && !defined(DOXYGEN_SKIP)
1000 #define CPL_NO_RETURN __attribute__((noreturn))
1004 #define CPL_NO_RETURN
1009 #ifndef __has_attribute
1010 #define __has_attribute(x) 0 // Compatibility with non-clang compilers.
1015 #if ((defined(__GNUC__) && \
1016 (__GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 9))) || \
1017 __has_attribute(returns_nonnull)) && \
1018 !defined(DOXYGEN_SKIP) && !defined(__INTEL_COMPILER)
1020 #define CPL_RETURNS_NONNULL __attribute__((returns_nonnull))
1023 #define CPL_RETURNS_NONNULL
1026 #if defined(__GNUC__) && __GNUC__ >= 4 && !defined(DOXYGEN_SKIP)
1028 #define CPL_RESTRICT __restrict__
1031 #define CPL_RESTRICT
1034 #if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
1038 #define CPL_OVERRIDE override
1041 #define CPL_FINAL final
1044 #define CPL_NON_FINAL
1051 #define CPL_DISALLOW_COPY_ASSIGN(ClassName) \
1052 ClassName(const ClassName &) = delete; \
1053 ClassName &operator=(const ClassName &) = delete;
1057 #if !defined(DOXYGEN_SKIP) && !defined(CPL_WARN_DEPRECATED)
1058 #if defined(__has_extension)
1059 #if __has_extension(attribute_deprecated_with_message)
1061 #define CPL_WARN_DEPRECATED(x) __attribute__((deprecated(x)))
1063 #define CPL_WARN_DEPRECATED(x)
1065 #elif defined(__GNUC__)
1066 #define CPL_WARN_DEPRECATED(x) __attribute__((deprecated))
1068 #define CPL_WARN_DEPRECATED(x)
1072 #if !defined(_MSC_VER) && !defined(__APPLE__) && !defined(_FORTIFY_SOURCE)
1074 #if defined(GDAL_COMPILATION) && defined(WARN_STANDARD_PRINTF)
1075 int vsnprintf(
char *str,
size_t size,
const char *fmt, va_list args)
1076 CPL_WARN_DEPRECATED(
"Use CPLvsnprintf() instead");
1077 int snprintf(
char *str,
size_t size,
const char *fmt, ...)
1082 #elif defined(GDAL_COMPILATION) && !defined(DONT_DEPRECATE_SPRINTF)
1084 CPL_WARN_DEPRECATED("Use snprintf() or
CPLsnprintf() instead");
1089 #if defined(MAKE_SANITIZE_HAPPY) || \
1090 !(defined(__i386__) || defined(__x86_64__) || defined(_M_IX86) || \
1093 #define CPL_CPU_REQUIRES_ALIGNED_ACCESS
1097 #if defined(__cplusplus)
1100 #define CPL_ARRAYSIZE(array) \
1101 ((sizeof(array) / sizeof(*(array))) / \
1102 static_cast<size_t>(!(sizeof(array) % sizeof(*(array)))))
1105 #define CPL_ARRAYSIZE(array) (sizeof(array) / sizeof(array[0]))
1110 template <
class T>
static void CPL_IGNORE_RET_VAL(
const T &)
1113 inline static bool CPL_TO_BOOL(
int x)
1121 #if (((__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) || \
1122 (defined(__clang__) && __clang_major__ >= 3)) && \
1124 #define HAVE_GCC_DIAGNOSTIC_PUSH
1127 #if ((__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2)) && \
1129 #define HAVE_GCC_SYSTEM_HEADER
1132 #if defined(__has_cpp_attribute)
1133 #if __has_cpp_attribute(fallthrough)
1135 #define CPL_FALLTHROUGH [[fallthrough]];
1137 #elif defined(__clang__) || __GNUC__ >= 7
1139 #define CPL_FALLTHROUGH [[clang::fallthrough]];
1141 #ifndef CPL_FALLTHROUGH
1143 #define CPL_FALLTHROUGH
1156 #if __clang_major__ >= 4 || (__clang_major__ == 3 && __clang_minor__ >= 8)
1157 #define CPL_NOSANITIZE_UNSIGNED_INT_OVERFLOW \
1158 __attribute__((no_sanitize("unsigned-integer-overflow")))
1160 #define CPL_NOSANITIZE_UNSIGNED_INT_OVERFLOW
1163 #if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS) && \
1164 defined(GDAL_COMPILATION)
1167 template <
class C,
class A,
class B>
1168 CPL_NOSANITIZE_UNSIGNED_INT_OVERFLOW
inline C CPLUnsanitizedAdd(A a, B b)
1175 #if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
1176 #define CPL_NULLPTR nullptr
1178 #define CPL_NULLPTR NULL
1187 #if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS) && \
1188 !defined(DOXYGEN_SKIP)
#define CPL_PRINT_FUNC_FORMAT(format_idx, arg_idx)
Tag a function to have printf() formatting.
Definition: cpl_port.h:959
unsigned char GByte
Unsigned byte type.
Definition: cpl_port.h:205
GUIntBig GUInt64
Unsigned 64 bit integer type.
Definition: cpl_port.h:258
short GInt16
Int16 type.
Definition: cpl_port.h:201
int CPLsnprintf(char *str, size_t size, const char *fmt,...)
snprintf() wrapper that is not sensitive to LC_NUMERIC settings.
Definition: cpl_string.cpp:1344
GIntBig GInt64
Signed 64 bit integer type.
Definition: cpl_port.h:256
int GPtrDiff_t
Integer type large enough to hold the difference between 2 addresses.
Definition: cpl_port.h:276
signed char GInt8
Signed int8 type.
Definition: cpl_port.h:207
#define CPL_C_START
Macro to start a block of C symbols.
Definition: cpl_port.h:315
char ** CSLConstList
Type of a constant null-terminated list of nul terminated strings.
Definition: cpl_port.h:1195
unsigned long long GUIntBig
Large unsigned integer type (generally 64-bit unsigned integer type).
Definition: cpl_port.h:238
#define CPLIsNan(x)
Return whether a floating-pointer number is NaN.
Definition: cpl_port.h:677
#define CPL_C_END
Macro to end a block of C symbols.
Definition: cpl_port.h:319
long long GIntBig
Large signed integer type (generally 64-bit integer type).
Definition: cpl_port.h:235
int GBool
Type for boolean values (alias to int)
Definition: cpl_port.h:216
#define CPLIsInf(x)
Return whether a floating-pointer number is +/- infinity.
Definition: cpl_port.h:680
unsigned short GUInt16
Unsigned int16 type.
Definition: cpl_port.h:203
int GInt32
Int32 type.
Definition: cpl_port.h:195
#define CPLIsFinite(x)
Return whether a floating-pointer number is finite.
Definition: cpl_port.h:682
unsigned int GUInt32
Unsigned int32 type.
Definition: cpl_port.h:197