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)
209#ifndef CPL_GBOOL_DEFINED
211#define CPL_GBOOL_DEFINED
219#define CPL_STATIC_CAST(type, expr) static_cast<type>(expr)
220#define CPL_REINTERPRET_CAST(type, expr) reinterpret_cast<type>(expr)
222#define CPL_STATIC_CAST(type, expr) ((type)(expr))
223#define CPL_REINTERPRET_CAST(type, expr) ((type)(expr))
239#define GINTBIG_MIN (CPL_STATIC_CAST(GIntBig, 0x80000000) << 32)
241#define GINTBIG_MAX ((CPL_STATIC_CAST(GIntBig, 0x7FFFFFFF) << 32) | 0xFFFFFFFFU)
243#define GUINTBIG_MAX \
244 ((CPL_STATIC_CAST(GUIntBig, 0xFFFFFFFFU) << 32) | 0xFFFFFFFFU)
247#define CPL_HAS_GINT64 1
259#define GINT64_MIN GINTBIG_MIN
261#define GINT64_MAX GINTBIG_MAX
263#define GUINT64_MAX GUINTBIG_MAX
269#elif SIZEOF_VOIDP == 8
277#ifdef GDAL_COMPILATION
279typedef uintptr_t GUIntptr_t;
280#define CPL_IS_ALIGNED(ptr, quant) \
281 ((CPL_REINTERPRET_CAST(GUIntptr_t, CPL_STATIC_CAST(const void *, ptr)) % \
286#if (defined(__MSVCRT__) && !(defined(__MINGW64__) && __GNUC__ >= 10)) || \
287 (defined(WIN32) && defined(_MSC_VER))
288#define CPL_FRMT_GB_WITHOUT_PREFIX "I64"
291#define CPL_FRMT_GB_WITHOUT_PREFIX "ll"
295#define CPL_FRMT_GIB "%" CPL_FRMT_GB_WITHOUT_PREFIX "d"
297#define CPL_FRMT_GUIB "%" CPL_FRMT_GB_WITHOUT_PREFIX "u"
300#ifdef COMPAT_WITH_ICC_CONVERSION_CHECK
301#define CPL_INT64_FITS_ON_INT32(x) ((x) >= INT_MIN && (x) <= INT_MAX)
303#define CPL_INT64_FITS_ON_INT32(x) \
304 (CPL_STATIC_CAST(GIntBig, CPL_STATIC_CAST(int, x)) == (x))
324#if defined(_MSC_VER) && !defined(CPL_DISABLE_DLL)
325#ifdef GDAL_COMPILATION
326#define CPL_DLL __declspec(dllexport)
332#if defined(USE_GCC_VISIBILITY_FLAG)
333#define CPL_DLL __attribute__((visibility("default")))
334#if !defined(__MINGW32__)
335#define CPL_INTERNAL __attribute__((visibility("hidden")))
346#define CPL_UNSTABLE_API CPL_DLL
352#ifdef CPL_OPTIONAL_APIS
353#define CPL_ODLL CPL_DLL
360#if defined(_MSC_VER) && !defined(CPL_DISABLE_STDCALL)
361#define CPL_STDCALL __stdcall
369#define FORCE_CDECL __cdecl
377#if (defined(__GNUC__) && !defined(__NO_INLINE__)) || defined(_MSC_VER)
378#define HAS_CPL_INLINE 1
379#define CPL_INLINE __inline
380#elif defined(__SUNPRO_CC)
381#define HAS_CPL_INLINE 1
382#define CPL_INLINE inline
390#define MIN(a, b) (((a) < (b)) ? (a) : (b))
392#define MAX(a, b) (((a) > (b)) ? (a) : (b))
397#define ABS(x) (((x) < 0) ? (-1 * (x)) : (x))
402#define M_PI 3.14159265358979323846
413#define CPLIsEqual(x, y) (fabs((x) - (y)) < 0.0000000000001)
422#if defined(AFL_FRIENDLY) && defined(__GNUC__)
424static inline int CPL_afl_friendly_memcmp(
const void *ptr1,
const void *ptr2,
426 __attribute__((always_inline));
428static inline int CPL_afl_friendly_memcmp(
const void *ptr1,
const void *ptr2,
431 const unsigned char *bptr1 = (
const unsigned char *)ptr1;
432 const unsigned char *bptr2 = (
const unsigned char *)ptr2;
435 unsigned char b1 = *(bptr1++);
436 unsigned char b2 = *(bptr2++);
443static inline int CPL_afl_friendly_strcmp(
const char *ptr1,
const char *ptr2)
444 __attribute__((always_inline));
446static inline int CPL_afl_friendly_strcmp(
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)
459static inline int CPL_afl_friendly_strncmp(
const char *ptr1,
const char *ptr2,
461 __attribute__((always_inline));
463static inline int CPL_afl_friendly_strncmp(
const char *ptr1,
const char *ptr2,
466 const unsigned char *usptr1 = (
const unsigned char *)ptr1;
467 const unsigned char *usptr2 = (
const unsigned char *)ptr2;
470 unsigned char ch1 = *(usptr1++);
471 unsigned char ch2 = *(usptr2++);
472 if (ch1 == 0 || ch1 != ch2)
478static inline int CPL_afl_friendly_strcasecmp(
const char *ptr1,
480 __attribute__((always_inline));
482static inline int CPL_afl_friendly_strcasecmp(
const char *ptr1,
485 const unsigned char *usptr1 = (
const unsigned char *)ptr1;
486 const unsigned char *usptr2 = (
const unsigned char *)ptr2;
489 unsigned char ch1 = *(usptr1++);
490 unsigned char ch2 = *(usptr2++);
491 ch1 = (
unsigned char)toupper(ch1);
492 ch2 = (
unsigned char)toupper(ch2);
493 if (ch1 == 0 || ch1 != ch2)
498static inline int CPL_afl_friendly_strncasecmp(
const char *ptr1,
499 const char *ptr2,
size_t len)
500 __attribute__((always_inline));
502static inline int CPL_afl_friendly_strncasecmp(
const char *ptr1,
503 const char *ptr2,
size_t len)
505 const unsigned char *usptr1 = (
const unsigned char *)ptr1;
506 const unsigned char *usptr2 = (
const unsigned char *)ptr2;
509 unsigned char ch1 = *(usptr1++);
510 unsigned char ch2 = *(usptr2++);
511 ch1 = (
unsigned char)toupper(ch1);
512 ch2 = (
unsigned char)toupper(ch2);
513 if (ch1 == 0 || ch1 != ch2)
519static inline char *CPL_afl_friendly_strstr(
const char *haystack,
521 __attribute__((always_inline));
523static inline char *CPL_afl_friendly_strstr(
const char *haystack,
526 const char *ptr_haystack = haystack;
529 const char *ptr_haystack2 = ptr_haystack;
530 const char *ptr_needle = needle;
533 char ch1 = *(ptr_haystack2++);
534 char ch2 = *(ptr_needle++);
536 return (
char *)ptr_haystack;
540 if (*ptr_haystack == 0)
548#define memcmp CPL_afl_friendly_memcmp
549#define strcmp CPL_afl_friendly_strcmp
550#define strncmp CPL_afl_friendly_strncmp
551#define strcasecmp CPL_afl_friendly_strcasecmp
552#define strncasecmp CPL_afl_friendly_strncasecmp
553#define strstr CPL_afl_friendly_strstr
558#define STRCASECMP(a, b) (_stricmp(a, b))
559#define STRNCASECMP(a, b, n) (_strnicmp(a, b, n))
562#define STRCASECMP(a, b) (strcasecmp(a, b))
564#define STRNCASECMP(a, b, n) (strncasecmp(a, b, n))
567#define EQUALN(a, b, n) (STRNCASECMP(a, b, n) == 0)
569#define EQUAL(a, b) (STRCASECMP(a, b) == 0)
576#ifndef STARTS_WITH_CI
578#define STARTS_WITH(a, b) (strncmp(a, b, strlen(b)) == 0)
580#define STARTS_WITH_CI(a, b) EQUALN(a, b, strlen(b))
584#ifndef CPL_THREADLOCAL
585#define CPL_THREADLOCAL
600#define CPLIsNan(x) _isnan(x)
601#define CPLIsInf(x) (!_isnan(x) && !_finite(x))
602#define CPLIsFinite(x) _finite(x)
603#elif defined(__GNUC__) && \
604 (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
607#define CPLIsNan(x) __builtin_isnan(x)
608#define CPLIsInf(x) __builtin_isinf(x)
609#define CPLIsFinite(x) __builtin_isfinite(x)
610#elif defined(__cplusplus) && defined(HAVE_STD_IS_NAN) && HAVE_STD_IS_NAN
618 return std::isnan(f);
620 static inline int CPLIsNan(
double f)
622 return std::isnan(f);
626 return std::isinf(f);
628 static inline int CPLIsInf(
double f)
630 return std::isinf(f);
634 return std::isfinite(f);
638 return std::isfinite(f);
643#if defined(__cplusplus) && defined(__GNUC__) && defined(__linux) && \
644 !defined(__ANDROID__) && !defined(CPL_SUPRESS_CPLUSPLUS)
653 static inline int CPLIsNan(
double f)
661 static inline int CPLIsInf(
double f)
667 return !__isnanf(f) && !__isinff(f);
671 return !__isnan(f) && !__isinf(f);
675#define CPLIsNan(x) isnan(x)
676#if defined(isinf) || defined(__FreeBSD__)
678#define CPLIsInf(x) isinf(x)
680#define CPLIsFinite(x) (!isnan(x) && !isinf(x))
681#elif defined(__sun__)
683#define CPLIsInf(x) (!finite(x) && !isnan(x))
684#define CPLIsFinite(x) finite(x)
686#define CPLIsInf(x) (0)
687#define CPLIsFinite(x) (!isnan(x))
700#if defined(WORDS_BIGENDIAN) && !defined(CPL_MSB) && !defined(CPL_LSB)
704#if !(defined(CPL_LSB) || defined(CPL_MSB))
715#if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
721 template <
bool b>
struct CPLStaticAssert
724 template <>
struct CPLStaticAssert<true>
726 static void my_function()
733#define CPL_STATIC_ASSERT(x) CPLStaticAssert<x>::my_function()
734#define CPL_STATIC_ASSERT_IF_AVAILABLE(x) CPL_STATIC_ASSERT(x)
738#define CPL_STATIC_ASSERT_IF_AVAILABLE(x)
748#define CPL_SWAP16(x) \
749 CPL_STATIC_CAST(GUInt16, (CPL_STATIC_CAST(GUInt16, x) << 8) | \
750 (CPL_STATIC_CAST(GUInt16, x) >> 8))
752#if defined(HAVE_GCC_BSWAP)
754#define CPL_SWAP32(x) \
755 CPL_STATIC_CAST(GUInt32, __builtin_bswap32(CPL_STATIC_CAST(GUInt32, x)))
757#define CPL_SWAP64(x) \
758 CPL_STATIC_CAST(GUInt64, __builtin_bswap64(CPL_STATIC_CAST(GUInt64, x)))
759#elif defined(_MSC_VER)
760#define CPL_SWAP32(x) \
761 CPL_STATIC_CAST(GUInt32, _byteswap_ulong(CPL_STATIC_CAST(GUInt32, x)))
762#define CPL_SWAP64(x) \
763 CPL_STATIC_CAST(GUInt64, _byteswap_uint64(CPL_STATIC_CAST(GUInt64, x)))
766#define CPL_SWAP32(x) \
767 CPL_STATIC_CAST(GUInt32, \
768 ((CPL_STATIC_CAST(GUInt32, x) & 0x000000ffU) << 24) | \
769 ((CPL_STATIC_CAST(GUInt32, x) & 0x0000ff00U) << 8) | \
770 ((CPL_STATIC_CAST(GUInt32, x) & 0x00ff0000U) >> 8) | \
771 ((CPL_STATIC_CAST(GUInt32, x) & 0xff000000U) >> 24))
774#define CPL_SWAP64(x) \
775 ((CPL_STATIC_CAST(GUInt64, CPL_SWAP32(CPL_STATIC_CAST(GUInt32, x))) \
777 (CPL_STATIC_CAST(GUInt64, \
778 CPL_SWAP32(CPL_STATIC_CAST( \
779 GUInt32, CPL_STATIC_CAST(GUInt64, x) >> 32)))))
784#define CPL_SWAP16PTR(x) \
789 memcpy(&_n16, _lx, 2); \
790 CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || \
791 sizeof(*(x)) == 2); \
792 _n16 = CPL_SWAP16(_n16); \
793 memcpy(_lx, &_n16, 2); \
797#define CPL_SWAP32PTR(x) \
802 memcpy(&_n32, _lx, 4); \
803 CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || \
804 sizeof(*(x)) == 4); \
805 _n32 = CPL_SWAP32(_n32); \
806 memcpy(_lx, &_n32, 4); \
810#define CPL_SWAP64PTR(x) \
815 memcpy(&_n64, _lx, 8); \
816 CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || \
817 sizeof(*(x)) == 8); \
818 _n64 = CPL_SWAP64(_n64); \
819 memcpy(_lx, &_n64, 8); \
823#define CPL_SWAPDOUBLE(p) CPL_SWAP64PTR(p)
826#define CPL_MSBWORD16(x) (x)
827#define CPL_LSBWORD16(x) CPL_SWAP16(x)
828#define CPL_MSBWORD32(x) (x)
829#define CPL_LSBWORD32(x) CPL_SWAP32(x)
830#define CPL_MSBPTR16(x) \
831 CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 2)
832#define CPL_LSBPTR16(x) CPL_SWAP16PTR(x)
833#define CPL_MSBPTR32(x) \
834 CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 4)
835#define CPL_LSBPTR32(x) CPL_SWAP32PTR(x)
836#define CPL_MSBPTR64(x) \
837 CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 8)
838#define CPL_LSBPTR64(x) CPL_SWAP64PTR(x)
841#define CPL_LSBWORD16(x) (x)
843#define CPL_MSBWORD16(x) CPL_SWAP16(x)
845#define CPL_LSBWORD32(x) (x)
847#define CPL_MSBWORD32(x) CPL_SWAP32(x)
850#define CPL_LSBPTR16(x) \
851 CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 2)
854#define CPL_MSBPTR16(x) CPL_SWAP16PTR(x)
857#define CPL_LSBPTR32(x) \
858 CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 4)
861#define CPL_MSBPTR32(x) CPL_SWAP32PTR(x)
864#define CPL_LSBPTR64(x) \
865 CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 8)
868#define CPL_MSBPTR64(x) CPL_SWAP64PTR(x)
874#define CPL_LSBINT16PTR(x) \
875 ((*CPL_REINTERPRET_CAST(const GByte *, x)) | \
876 (*((CPL_REINTERPRET_CAST(const GByte *, x)) + 1) << 8))
881#define CPL_LSBINT32PTR(x) \
882 ((*CPL_REINTERPRET_CAST(const GByte *, x)) | \
883 (*((CPL_REINTERPRET_CAST(const GByte *, x)) + 1) << 8) | \
884 (*((CPL_REINTERPRET_CAST(const GByte *, x)) + 2) << 16) | \
885 (*((CPL_REINTERPRET_CAST(const GByte *, x)) + 3) << 24))
888#define CPL_LSBSINT16PTR(x) CPL_STATIC_CAST(GInt16, CPL_LSBINT16PTR(x))
892#define CPL_LSBUINT16PTR(x) CPL_STATIC_CAST(GUInt16, CPL_LSBINT16PTR(x))
895#define CPL_LSBSINT32PTR(x) CPL_STATIC_CAST(GInt32, CPL_LSBINT32PTR(x))
899#define CPL_LSBUINT32PTR(x) CPL_STATIC_CAST(GUInt32, CPL_LSBINT32PTR(x))
903#ifndef UNREFERENCED_PARAM
904#ifdef UNREFERENCED_PARAMETER
905#define UNREFERENCED_PARAM(param) UNREFERENCED_PARAMETER(param)
907#define UNREFERENCED_PARAM(param) ((void)param)
922#if defined(__GNUC__) && __GNUC__ >= 4
923#define CPL_CVSID(string) \
924 static const char cpl_cvsid[] __attribute__((used)) = string;
926#define CPL_CVSID(string) \
927 static const char cpl_cvsid[] = string; \
928 static const char *cvsid_aw() \
930 return (cvsid_aw() ? NULL : cpl_cvsid); \
934#define CPL_CVSID(string)
939#if defined(__GNUC__) && __GNUC__ >= 4 && !defined(DOXYGEN_SKIP) && \
940 !(defined(__MINGW64__) && __GNUC__ == 4 && __GNUC_MINOR__ == 6)
942#define CPL_NULL_TERMINATED __attribute__((__sentinel__))
945#define CPL_NULL_TERMINATED
948#if defined(__GNUC__) && __GNUC__ >= 3 && !defined(DOXYGEN_SKIP)
950#define CPL_PRINT_FUNC_FORMAT(format_idx, arg_idx) \
951 __attribute__((__format__(__printf__, format_idx, arg_idx)))
953#define CPL_SCAN_FUNC_FORMAT(format_idx, arg_idx) \
954 __attribute__((__format__(__scanf__, format_idx, arg_idx)))
957#define CPL_PRINT_FUNC_FORMAT(format_idx, arg_idx)
959#define CPL_SCAN_FUNC_FORMAT(format_idx, arg_idx)
962#if defined(_MSC_VER) && \
963 (defined(GDAL_COMPILATION) || defined(CPL_ENABLE_MSVC_ANNOTATIONS))
967#define CPL_FORMAT_STRING(arg) _Printf_format_string_ arg
970#define CPL_SCANF_FORMAT_STRING(arg) _Scanf_format_string_ arg
973#define CPL_FORMAT_STRING(arg) arg
975#define CPL_SCANF_FORMAT_STRING(arg) arg
978#if defined(__GNUC__) && __GNUC__ >= 4 && !defined(DOXYGEN_SKIP)
980#define CPL_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
983#define CPL_WARN_UNUSED_RESULT
986#if defined(__GNUC__) && __GNUC__ >= 4
988#define CPL_UNUSED __attribute((__unused__))
995#if defined(__GNUC__) && __GNUC__ >= 3 && !defined(DOXYGEN_SKIP)
998#define CPL_NO_RETURN __attribute__((noreturn))
1002#define CPL_NO_RETURN
1007#ifndef __has_attribute
1008#define __has_attribute(x) 0
1013#if ((defined(__GNUC__) && \
1014 (__GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 9))) || \
1015 __has_attribute(returns_nonnull)) && \
1016 !defined(DOXYGEN_SKIP) && !defined(__INTEL_COMPILER)
1018#define CPL_RETURNS_NONNULL __attribute__((returns_nonnull))
1021#define CPL_RETURNS_NONNULL
1024#if defined(__GNUC__) && __GNUC__ >= 4 && !defined(DOXYGEN_SKIP)
1026#define CPL_RESTRICT __restrict__
1032#if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
1036#define CPL_OVERRIDE override
1039#define CPL_FINAL final
1042#define CPL_NON_FINAL
1049#define CPL_DISALLOW_COPY_ASSIGN(ClassName) \
1050 ClassName(const ClassName &) = delete; \
1051 ClassName &operator=(const ClassName &) = delete;
1055#if !defined(DOXYGEN_SKIP) && !defined(CPL_WARN_DEPRECATED)
1056#if defined(__has_extension)
1057#if __has_extension(attribute_deprecated_with_message)
1059#define CPL_WARN_DEPRECATED(x) __attribute__((deprecated(x)))
1061#define CPL_WARN_DEPRECATED(x)
1063#elif defined(__GNUC__)
1064#define CPL_WARN_DEPRECATED(x) __attribute__((deprecated))
1066#define CPL_WARN_DEPRECATED(x)
1070#if !defined(_MSC_VER) && !defined(__APPLE__) && !defined(_FORTIFY_SOURCE)
1072#if defined(GDAL_COMPILATION) && defined(WARN_STANDARD_PRINTF)
1073int vsnprintf(
char *str,
size_t size,
const char *fmt, va_list args)
1074 CPL_WARN_DEPRECATED(
"Use CPLvsnprintf() instead");
1075int snprintf(
char *str,
size_t size,
const char *fmt, ...)
1077 CPL_WARN_DEPRECATED("Use CPLsnprintf() instead");
1079 CPL_WARN_DEPRECATED("Use CPLsnprintf() instead");
1080#elif defined(GDAL_COMPILATION) && !defined(DONT_DEPRECATE_SPRINTF)
1082 CPL_WARN_DEPRECATED("Use snprintf() or CPLsnprintf() instead");
1087#if defined(MAKE_SANITIZE_HAPPY) || \
1088 !(defined(__i386__) || defined(__x86_64__) || defined(_M_IX86) || \
1091#define CPL_CPU_REQUIRES_ALIGNED_ACCESS
1095#if defined(__cplusplus)
1098#define CPL_ARRAYSIZE(array) \
1099 ((sizeof(array) / sizeof(*(array))) / \
1100 static_cast<size_t>(!(sizeof(array) % sizeof(*(array)))))
1103#define CPL_ARRAYSIZE(array) (sizeof(array) / sizeof(array[0]))
1108 template <
class T>
static void CPL_IGNORE_RET_VAL(
const T &)
1111 inline static bool CPL_TO_BOOL(
int x)
1119#if (((__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) || \
1120 (defined(__clang__) && __clang_major__ >= 3)) && \
1122#define HAVE_GCC_DIAGNOSTIC_PUSH
1125#if ((__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2)) && \
1127#define HAVE_GCC_SYSTEM_HEADER
1130#if ((defined(__clang__) && \
1131 (__clang_major__ > 3 || \
1132 (__clang_major__ == 3 && __clang_minor__ >= 7))) || \
1135#define CPL_FALLTHROUGH [[clang::fallthrough]];
1138#define CPL_FALLTHROUGH
1151#if __clang_major__ >= 4 || (__clang_major__ == 3 && __clang_minor__ >= 8)
1152#define CPL_NOSANITIZE_UNSIGNED_INT_OVERFLOW \
1153 __attribute__((no_sanitize("unsigned-integer-overflow")))
1155#define CPL_NOSANITIZE_UNSIGNED_INT_OVERFLOW
1158#if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS) && \
1159 defined(GDAL_COMPILATION)
1162 template <
class C,
class A,
class B>
1163 CPL_NOSANITIZE_UNSIGNED_INT_OVERFLOW
inline C CPLUnsanitizedAdd(A a, B b)
1170#if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
1171#define CPL_NULLPTR nullptr
1173#define CPL_NULLPTR NULL
1182#if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS) && \
1183 !defined(DOXYGEN_SKIP)
int GPtrDiff_t
Integer type large enough to hold the difference between 2 addresses.
Definition cpl_port.h:274
#define CPLIsInf(x)
Return whether a floating-pointer number is +/- infinity.
Definition cpl_port.h:678
unsigned long long GUIntBig
Large unsigned integer type (generally 64-bit unsigned integer type).
Definition cpl_port.h:236
short GInt16
Int16 type.
Definition cpl_port.h:201
#define CPL_C_END
Macro to end a block of C symbols.
Definition cpl_port.h:317
#define CPL_C_START
Macro to start a block of C symbols.
Definition cpl_port.h:313
GIntBig GInt64
Signed 64 bit integer type.
Definition cpl_port.h:254
int GBool
Type for boolean values (alias to int)
Definition cpl_port.h:214
unsigned int GUInt32
Unsigned int32 type.
Definition cpl_port.h:197
#define CPL_PRINT_FUNC_FORMAT(format_idx, arg_idx)
Tag a function to have printf() formatting.
Definition cpl_port.h:957
#define CPLIsNan(x)
Return whether a floating-pointer number is NaN.
Definition cpl_port.h:675
char ** CSLConstList
Type of a constant null-terminated list of nul terminated strings.
Definition cpl_port.h:1190
GUIntBig GUInt64
Unsigned 64 bit integer type.
Definition cpl_port.h:256
unsigned short GUInt16
Unsigned int16 type.
Definition cpl_port.h:203
unsigned char GByte
Unsigned byte type.
Definition cpl_port.h:205
int GInt32
Int32 type.
Definition cpl_port.h:195
long long GIntBig
Large signed integer type (generally 64-bit integer type).
Definition cpl_port.h:233
#define CPLIsFinite(x)
Return whether a floating-pointer number is finite.
Definition cpl_port.h:680