SDL_stdinc.h File Reference
`#include <SDL3/SDL_platform_defines.h>`
`#include <stdarg.h>`
`#include <string.h>`
`#include <wchar.h>`
`#include <stdint.h>`
`#include <SDL3/SDL_begin_code.h>`
`#include <SDL3/SDL_close_code.h>`
Include dependency graph for SDL_stdinc.h:

Go to the source code of this file.

## Macros

#define | bool unsigned char
#define | false 0
#define | true 1
#define | __bool_true_false_are_defined 1
#define | SDL_SIZE_MAX ((size_t) -1)
#define | SDL_COMPILE_TIME_ASSERT(name, x)
#define | SDL_arraysize(array)
#define | SDL_STRINGIFY_ARG(arg)
Cast operators
Use proper C++ casts when compiled as C++ to be compatible with the option -Wold-style-cast of GCC (and -Werror=old-style-cast in GCC 4.2 and above).
#define | SDL_reinterpret_cast(type, expression)
#define | SDL_static_cast(type, expression)
#define | SDL_const_cast(type, expression)
#define | SDL_FOURCC(A, B, C, D)
#define | SDL_SINT64_C(c)
#define | SDL_UINT64_C(c)

## Functions

void * | alloca (size_t)

## Basic data types

#define | SDL_MAX_SINT8 ((Sint8)0x7F) /* 127 */
#define | SDL_MIN_SINT8 ((Sint8)(~0x7F)) /* -128 */
#define | SDL_MAX_UINT8 ((Uint8)0xFF) /* 255 */
#define | SDL_MIN_UINT8 ((Uint8)0x00) /* 0 */
#define | SDL_MAX_SINT16 ((Sint16)0x7FFF) /* 32767 */
#define | SDL_MIN_SINT16 ((Sint16)(~0x7FFF)) /* -32768 */
#define | SDL_MAX_UINT16 ((Uint16)0xFFFF) /* 65535 */
#define | SDL_MIN_UINT16 ((Uint16)0x0000) /* 0 */
#define | SDL_MAX_SINT32 ((Sint32)0x7FFFFFFF) /* 2147483647 */
#define | SDL_MIN_SINT32 ((Sint32)(~0x7FFFFFFF)) /* -2147483648 */
#define | SDL_MAX_UINT32 ((Uint32)0xFFFFFFFFu) /* 4294967295 */
#define | SDL_MIN_UINT32 ((Uint32)0x00000000) /* 0 */
#define | SDL_MAX_SINT64 SDL_SINT64_C(0x7FFFFFFFFFFFFFFF) /* 9223372036854775807 */
#define | SDL_MIN_SINT64 ~SDL_SINT64_C(0x7FFFFFFFFFFFFFFF) /* -9223372036854775808 */
#define | SDL_MAX_UINT64 SDL_UINT64_C(0xFFFFFFFFFFFFFFFF) /* 18446744073709551615 */
#define | SDL_MIN_UINT64 SDL_UINT64_C(0x0000000000000000) /* 0 */
#define | SDL_MAX_TIME SDL_MAX_SINT64
#define | SDL_MIN_TIME SDL_MIN_SINT64
typedef int8_t | Sint8
typedef uint8_t | Uint8
typedef int16_t | Sint16
typedef uint16_t | Uint16
typedef int32_t | Sint32
typedef uint32_t | Uint32
typedef int64_t | Sint64
typedef uint64_t | Uint64
typedef Sint64 | SDL_Time

## Floating-point constants

#define | SDL_FLT_EPSILON 1.1920928955078125e-07F /* 0x0.000002p0 */
#define | SDL_PRIs64 "lld"
#define | SDL_PRIu64 "llu"
#define | SDL_PRIx64 "llx"
#define | SDL_PRIX64 "llX"
#define | SDL_PRIs32 "d"
#define | SDL_PRIu32 "u"
#define | SDL_PRIx32 "x"
#define | SDL_PRIX32 "X"
#define | SDL_PRILL_PREFIX "ll"
#define | SDL_PRILLd SDL_PRILL_PREFIX "d"
#define | SDL_PRILLu SDL_PRILL_PREFIX "u"
#define | SDL_PRILLx SDL_PRILL_PREFIX "x"
#define | SDL_PRILLX SDL_PRILL_PREFIX "X"
#define | SDL_IN_BYTECAP(x)
#define | SDL_INOUT_Z_CAP(x)
#define | SDL_OUT_Z_CAP(x)
#define | SDL_OUT_CAP(x)
#define | SDL_OUT_BYTECAP(x)
#define | SDL_OUT_Z_BYTECAP(x)
#define | SDL_PRINTF_FORMAT_STRING
#define | SDL_SCANF_FORMAT_STRING
#define | SDL_PRINTF_VARARG_FUNC(fmtargnumber)
#define | SDL_PRINTF_VARARG_FUNCV(fmtargnumber)
#define | SDL_SCANF_VARARG_FUNC(fmtargnumber)
#define | SDL_SCANF_VARARG_FUNCV(fmtargnumber)
#define | SDL_WPRINTF_VARARG_FUNC(fmtargnumber)
#define | SDL_WPRINTF_VARARG_FUNCV(fmtargnumber)
#define | SDL_INIT_INTERFACE(iface)
#define | SDL_stack_alloc(type, count)
#define | SDL_stack_free(data)
#define | SDL_min(x, y)
#define | SDL_max(x, y)
#define | SDL_clamp(x, a, b)
#define | SDL_memcpy memcpy
#define | SDL_copyp(dst, src)
#define | SDL_memmove memmove
#define | SDL_memset memset
#define | SDL_zero(x)
#define | SDL_zerop(x)
#define | SDL_zeroa(x)
#define | SDL_INVALID_UNICODE_CODEPOINT 0xFFFD
#define | SDL_PI_D 3.141592653589793238462643383279502884
#define | SDL_PI_F 3.141592653589793238462643383279502884F
#define | SDL_ICONV_ERROR (size_t)-1
#define | SDL_ICONV_E2BIG (size_t)-2
#define | SDL_ICONV_EILSEQ (size_t)-3
#define | SDL_ICONV_EINVAL (size_t)-4
#define | SDL_iconv_utf8_locale(S)
#define | SDL_iconv_utf8_ucs2(S)
#define | SDL_iconv_utf8_ucs4(S)
#define | SDL_iconv_wchar_utf8(S)
typedef void *(* | SDL_malloc_func) (size_t size)
typedef void *(* | SDL_calloc_func) (size_t nmemb, size_t size)
typedef void *(* | SDL_realloc_func) (void *mem, size_t size)
typedef void(* | SDL_free_func) (void *mem)
typedef struct SDL_Environment | SDL_Environment
typedef int(* | SDL_CompareCallback) (const void *a, const void *b)
typedef int(* | SDL_CompareCallback_r) (void *userdata, const void *a, const void *b)
typedef struct SDL_iconv_data_t * | SDL_iconv_t
typedef void(* | SDL_FunctionPointer) (void)
SDL_MALLOC size_t | size
SDL_MALLOC void * | SDL_malloc (size_t size)
SDL_MALLOC | SDL_ALLOC_SIZE2 (1, 2) void *SDL_calloc(size_t nmemb
| SDL_ALLOC_SIZE (2) void *SDL_realloc(void *mem
void | SDL_free (void *mem)
void | SDL_GetOriginalMemoryFunctions (SDL_malloc_func *malloc_func, SDL_calloc_func *calloc_func, SDL_realloc_func *realloc_func, SDL_free_func *free_func)
void | SDL_GetMemoryFunctions (SDL_malloc_func *malloc_func, SDL_calloc_func *calloc_func, SDL_realloc_func *realloc_func, SDL_free_func *free_func)
bool | SDL_SetMemoryFunctions (SDL_malloc_func malloc_func, SDL_calloc_func calloc_func, SDL_realloc_func realloc_func, SDL_free_func free_func)
SDL_MALLOC void * | SDL_aligned_alloc (size_t alignment, size_t size)
void | SDL_aligned_free (void *mem)
int | SDL_GetNumAllocations (void)
SDL_Environment * | SDL_GetEnvironment (void)
SDL_Environment * | SDL_CreateEnvironment (bool populated)
const char * | SDL_GetEnvironmentVariable (SDL_Environment *env, const char *name)
char ** | SDL_GetEnvironmentVariables (SDL_Environment *env)
bool | SDL_SetEnvironmentVariable (SDL_Environment *env, const char *name, const char *value, bool overwrite)
bool | SDL_UnsetEnvironmentVariable (SDL_Environment *env, const char *name)
void | SDL_DestroyEnvironment (SDL_Environment *env)
const char * | SDL_getenv (const char *name)
const char * | SDL_getenv_unsafe (const char *name)
int | SDL_setenv_unsafe (const char *name, const char *value, int overwrite)
int | SDL_unsetenv_unsafe (const char *name)
void | SDL_qsort (void *base, size_t nmemb, size_t size, SDL_CompareCallback compare)
void * | SDL_bsearch (const void *key, const void *base, size_t nmemb, size_t size, SDL_CompareCallback compare)
void | SDL_qsort_r (void *base, size_t nmemb, size_t size, SDL_CompareCallback_r compare, void *userdata)
void * | SDL_bsearch_r (const void *key, const void *base, size_t nmemb, size_t size, SDL_CompareCallback_r compare, void *userdata)
int | SDL_abs (int x)
int | SDL_isalpha (int x)
int | SDL_isalnum (int x)
int | SDL_isblank (int x)
int | SDL_iscntrl (int x)
int | SDL_isdigit (int x)
int | SDL_isxdigit (int x)
int | SDL_ispunct (int x)
int | SDL_isspace (int x)
int | SDL_isupper (int x)
int | SDL_islower (int x)
int | SDL_isprint (int x)
int | SDL_isgraph (int x)
int | SDL_toupper (int x)
int | SDL_tolower (int x)
Uint16 | SDL_crc16 (Uint16 crc, const void *data, size_t len)
Uint32 | SDL_crc32 (Uint32 crc, const void *data, size_t len)
Uint32 | SDL_murmur3_32 (const void *data, size_t len, Uint32 seed)
void * | SDL_memcpy (SDL_OUT_BYTECAP(len) void *dst, SDL_IN_BYTECAP(len) const void *src, size_t len)
void * | SDL_memmove (SDL_OUT_BYTECAP(len) void *dst, SDL_IN_BYTECAP(len) const void *src, size_t len)
void * | SDL_memset (SDL_OUT_BYTECAP(len) void *dst, int c, size_t len)
void * | SDL_memset4 (void *dst, Uint32 val, size_t dwords)
int | SDL_memcmp (const void *s1, const void *s2, size_t len)
size_t | SDL_wcslen (const wchar_t *wstr)
size_t | SDL_wcsnlen (const wchar_t *wstr, size_t maxlen)
size_t | SDL_wcslcpy (SDL_OUT_Z_CAP(maxlen) wchar_t *dst, const wchar_t *src, size_t maxlen)
size_t | SDL_wcslcat (SDL_INOUT_Z_CAP(maxlen) wchar_t *dst, const wchar_t *src, size_t maxlen)
wchar_t * | SDL_wcsdup (const wchar_t *wstr)
wchar_t * | SDL_wcsstr (const wchar_t *haystack, const wchar_t *needle)
wchar_t * | SDL_wcsnstr (const wchar_t *haystack, const wchar_t *needle, size_t maxlen)
int | SDL_wcscmp (const wchar_t *str1, const wchar_t *str2)
int | SDL_wcsncmp (const wchar_t *str1, const wchar_t *str2, size_t maxlen)
int | SDL_wcscasecmp (const wchar_t *str1, const wchar_t *str2)
int | SDL_wcsncasecmp (const wchar_t *str1, const wchar_t *str2, size_t maxlen)
long | SDL_wcstol (const wchar_t *str, wchar_t **endp, int base)
size_t | SDL_strlen (const char *str)
size_t | SDL_strnlen (const char *str, size_t maxlen)
size_t | SDL_strlcpy (SDL_OUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen)
size_t | SDL_utf8strlcpy (SDL_OUT_Z_CAP(dst_bytes) char *dst, const char *src, size_t dst_bytes)
size_t | SDL_strlcat (SDL_INOUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen)
SDL_MALLOC char * | SDL_strdup (const char *str)
SDL_MALLOC char * | SDL_strndup (const char *str, size_t maxlen)
char * | SDL_strrev (char *str)
char * | SDL_strupr (char *str)
char * | SDL_strlwr (char *str)
char * | SDL_strchr (const char *str, int c)
char * | SDL_strrchr (const char *str, int c)
char * | SDL_strstr (const char *haystack, const char *needle)
char * | SDL_strnstr (const char *haystack, const char *needle, size_t maxlen)
char * | SDL_strcasestr (const char *haystack, const char *needle)
char * | SDL_strtok_r (char *str, const char *delim, char **saveptr)
size_t | SDL_utf8strlen (const char *str)
size_t | SDL_utf8strnlen (const char *str, size_t bytes)
char * | SDL_itoa (int value, char *str, int radix)
char * | SDL_uitoa (unsigned int value, char *str, int radix)
char * | SDL_ltoa (long value, char *str, int radix)
char * | SDL_ultoa (unsigned long value, char *str, int radix)
char * | SDL_lltoa (long long value, char *str, int radix)
char * | SDL_ulltoa (unsigned long long value, char *str, int radix)
int | SDL_atoi (const char *str)
double | SDL_atof (const char *str)
long | SDL_strtol (const char *str, char **endp, int base)
unsigned long | SDL_strtoul (const char *str, char **endp, int base)
long long | SDL_strtoll (const char *str, char **endp, int base)
unsigned long long | SDL_strtoull (const char *str, char **endp, int base)
double | SDL_strtod (const char *str, char **endp)
int | SDL_strcmp (const char *str1, const char *str2)
int | SDL_strncmp (const char *str1, const char *str2, size_t maxlen)
int | SDL_strcasecmp (const char *str1, const char *str2)
int | SDL_strncasecmp (const char *str1, const char *str2, size_t maxlen)
char * | SDL_strpbrk (const char *str, const char *breakset)
Uint32 | SDL_StepUTF8 (const char **pstr, size_t *pslen)
Uint32 | SDL_StepBackUTF8 (const char *start, const char **pstr)
char * | SDL_UCS4ToUTF8 (Uint32 codepoint, char *dst)
int | SDL_sscanf (const char *text, SDL_SCANF_FORMAT_STRING const char *fmt,...) SDL_SCANF_VARARG_FUNC(2)
int | SDL_vsscanf (const char *text, SDL_SCANF_FORMAT_STRING const char *fmt, va_list ap) SDL_SCANF_VARARG_FUNCV(2)
int | SDL_snprintf (SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, SDL_PRINTF_FORMAT_STRING const char *fmt,...) SDL_PRINTF_VARARG_FUNC(3)
int | SDL_swprintf (SDL_OUT_Z_CAP(maxlen) wchar_t *text, size_t maxlen, SDL_PRINTF_FORMAT_STRING const wchar_t *fmt,...) SDL_WPRINTF_VARARG_FUNC(3)
int | SDL_vsnprintf (SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, SDL_PRINTF_FORMAT_STRING const char *fmt, va_list ap) SDL_PRINTF_VARARG_FUNCV(3)
int | SDL_vswprintf (SDL_OUT_Z_CAP(maxlen) wchar_t *text, size_t maxlen, SDL_PRINTF_FORMAT_STRING const wchar_t *fmt, va_list ap) SDL_WPRINTF_VARARG_FUNCV(3)
int | SDL_asprintf (char **strp, SDL_PRINTF_FORMAT_STRING const char *fmt,...) SDL_PRINTF_VARARG_FUNC(2)
int | SDL_vasprintf (char **strp, SDL_PRINTF_FORMAT_STRING const char *fmt, va_list ap) SDL_PRINTF_VARARG_FUNCV(2)
void | SDL_srand (Uint64 seed)
Sint32 | SDL_rand (Sint32 n)
float | SDL_randf (void)
Uint32 | SDL_rand_bits (void)
Sint32 | SDL_rand_r (Uint64 *state, Sint32 n)
float | SDL_randf_r (Uint64 *state)
Uint32 | SDL_rand_bits_r (Uint64 *state)
double | SDL_acos (double x)
float | SDL_acosf (float x)
double | SDL_asin (double x)
float | SDL_asinf (float x)
double | SDL_atan (double x)
float | SDL_atanf (float x)
double | SDL_atan2 (double y, double x)
float | SDL_atan2f (float y, float x)
double | SDL_ceil (double x)
float | SDL_ceilf (float x)
double | SDL_copysign (double x, double y)
float | SDL_copysignf (float x, float y)
double | SDL_cos (double x)
float | SDL_cosf (float x)
double | SDL_exp (double x)
float | SDL_expf (float x)
double | SDL_fabs (double x)
float | SDL_fabsf (float x)
double | SDL_floor (double x)
float | SDL_floorf (float x)
double | SDL_trunc (double x)
float | SDL_truncf (float x)
double | SDL_fmod (double x, double y)
float | SDL_fmodf (float x, float y)
int | SDL_isinf (double x)
int | SDL_isinff (float x)
int | SDL_isnan (double x)
int | SDL_isnanf (float x)
double | SDL_log (double x)
float | SDL_logf (float x)
double | SDL_log10 (double x)
float | SDL_log10f (float x)
double | SDL_modf (double x, double *y)
float | SDL_modff (float x, float *y)
double | SDL_pow (double x, double y)
float | SDL_powf (float x, float y)
double | SDL_round (double x)
float | SDL_roundf (float x)
long | SDL_lround (double x)
long | SDL_lroundf (float x)
double | SDL_scalbn (double x, int n)
float | SDL_scalbnf (float x, int n)
double | SDL_sin (double x)
float | SDL_sinf (float x)
double | SDL_sqrt (double x)
float | SDL_sqrtf (float x)
double | SDL_tan (double x)
float | SDL_tanf (float x)
SDL_iconv_t | SDL_iconv_open (const char *tocode, const char *fromcode)
int | SDL_iconv_close (SDL_iconv_t cd)
size_t | SDL_iconv (SDL_iconv_t cd, const char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft)
char * | SDL_iconv_string (const char *tocode, const char *fromcode, const char *inbuf, size_t inbytesleft)
SDL_FORCE_INLINE bool | SDL_size_mul_check_overflow (size_t a, size_t b, size_t *ret)
SDL_FORCE_INLINE bool | SDL_size_add_check_overflow (size_t a, size_t b, size_t *ret)

## Macro Definition Documentation

## __bool_true_false_are_defined

#define __bool_true_false_are_defined 1

Definition at line 102 of file SDL_stdinc.h.

## bool

#define bool unsigned char

# CategoryStdinc

SDL provides its own implementation of some of the most important C runtime functions.

Using these functions allows an app to have access to common C functionality without depending on a specific C runtime (or a C runtime at all). More importantly, the SDL implementations work identically across platforms, so apps can avoid surprises like snprintf() behaving differently between Windows and Linux builds, or itoa() only existing on some platforms.

For many of the most common functions, like SDL_memcpy, SDL might just call through to the usual C runtime behind the scenes, if it makes sense to do so (if it's faster and always available/reliable on a given platform), reducing library size and offering the most optimized option.

SDL also offers other C-runtime-adjacent functionality in this header that either isn't, strictly speaking, part of any C runtime standards, like SDL_crc32() and SDL_reinterpret_cast, etc. It also offers a few better options, like SDL_strlcpy(), which functions as a safer form of strcpy().

Definition at line 99 of file SDL_stdinc.h.

## false

#define false 0

Definition at line 100 of file SDL_stdinc.h.

## SDL_arraysize

#define SDL_arraysize | ( |  | array | ) |

Value:
(sizeof(array)/sizeof(array[0]))

The number of elements in a static array.

This will compile but return incorrect results for a pointer to an array; it has to be an array the compiler knows the size of.

This macro looks like it double-evaluates the argument, but it does so inside of sizeof, so there are no side-effects here, as expressions do not actually run any code in these cases.

Since
  This macro is available since SDL 3.2.0.

Definition at line 252 of file SDL_stdinc.h.

## SDL_clamp

#define SDL_clamp | ( |  | x,
|  |  | a,
|  |  | b )

Value:
(((x) < (a)) ? (a) : (((x) > (b)) ? (b) : (x)))

Return a value clamped to a range.

If x is outside the range a values between a and b, the returned value will be a or b as appropriate. Otherwise, x is returned.

This macro will produce incorrect results if b is less than a.

This is a helper macro that might be more clear than writing out the comparisons directly, and works with any type that can be compared with the < and > operators. However, it double-evaluates all its parameters, so do not use expressions with side-effects here.

Parameters

  x | the value to compare.
  a | the low end value.
  b | the high end value.

Returns
  x, clamped between a and b.

\threadsafety It is safe to call this macro from any thread.

Since
  This macro is available since SDL 3.2.0.

Definition at line 2181 of file SDL_stdinc.h.

## SDL_COMPILE_TIME_ASSERT

#define SDL_COMPILE_TIME_ASSERT | ( |  | name,
|  |  | x )

Value:
typedef int SDL_compile_time_assert_ ## name[(x) * 2 - 1]

Definition at line 236 of file SDL_stdinc.h.

#define SDL_COMPILE_TIME_ASSERT(name, x) \
typedef int SDL_compile_time_assert_ ## name[(x) * 2 - 1]

## SDL_const_cast

#define SDL_const_cast | ( |  | type,
|  |  | expression )

Value:
((type)(expression))

Definition at line 346 of file SDL_stdinc.h.

## SDL_copyp

#define SDL_copyp | ( |  | dst,
|  |  | src )

Value:
{ SDL_COMPILE_TIME_ASSERT(SDL_copyp, sizeof (*(dst)) == sizeof (*(src))); } \
SDL_memcpy((dst), (src), sizeof(*(src)))
SDL_copyp
#define SDL_copyp(dst, src)
Definition SDL_stdinc.h:2540
SDL_COMPILE_TIME_ASSERT
#define SDL_COMPILE_TIME_ASSERT(name, x)
Definition SDL_stdinc.h:236

A macro to copy memory between objects, with basic type checking.

SDL_memcpy and SDL_memmove do not care where you copy memory to and from, which can lead to bugs. This macro aims to avoid most of those bugs by making sure that the source and destination are both pointers to objects that are the same size. It does not check that the objects are the same type, just that the copy will not overflow either object.

The size check happens at compile time, and the compiler will throw an error if the objects are different sizes.

Generally this is intended to copy a single object, not an array.

This macro looks like it double-evaluates its parameters, but the extras them are in sizeof sections, which generate no code nor side-effects.

Parameters

  dst | a pointer to the destination object. Must not be NULL.
  src | a pointer to the source object. Must not be NULL.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

Definition at line 2540 of file SDL_stdinc.h.

#define SDL_copyp(dst, src) \
{ SDL_COMPILE_TIME_ASSERT(SDL_copyp, sizeof (*(dst)) == sizeof (*(src))); } \
SDL_memcpy((dst), (src), sizeof(*(src)))

## SDL_FLT_EPSILON

#define SDL_FLT_EPSILON 1.1920928955078125e-07F /* 0x0.000002p0 */

Epsilon constant, used for comparing floating-point numbers.

Equals by default to platform-defined FLT_EPSILON, or 1.1920928955078125e-07F if that's not available.

Since
  This macro is available since SDL 3.2.0.

Definition at line 544 of file SDL_stdinc.h.

Referenced by SDL_RectsEqualFloat().

## SDL_FOURCC

#define SDL_FOURCC | ( |  | A,
|  |  | B,
|  |  | C,
|  |  | D )

Value:
((SDL_static_cast(Uint32, SDL_static_cast(Uint8, (A))) << 0) | \
(SDL_static_cast(Uint32, SDL_static_cast(Uint8, (B))) << 8) | \
(SDL_static_cast(Uint32, SDL_static_cast(Uint8, (C))) << 16) | \
(SDL_static_cast(Uint32, SDL_static_cast(Uint8, (D))) << 24))
Uint8
uint8_t Uint8
Definition SDL_stdinc.h:446
SDL_static_cast
#define SDL_static_cast(type, expression)
Definition SDL_stdinc.h:345
Uint32
uint32_t Uint32
Definition SDL_stdinc.h:482

Define a four character code as a Uint32.

Parameters

  A | the first ASCII character.
  B | the second ASCII character.
  C | the third ASCII character.
  D | the fourth ASCII character.

Returns
  the four characters converted into a Uint32, one character per-byte.

\threadsafety It is safe to call this macro from any thread.

Since
  This macro is available since SDL 3.2.0.

Definition at line 365 of file SDL_stdinc.h.

#define SDL_FOURCC(A, B, C, D) \
((SDL_static_cast(Uint32, SDL_static_cast(Uint8, (A))) << 0) | \
(SDL_static_cast(Uint32, SDL_static_cast(Uint8, (B))) << 8) | \
(SDL_static_cast(Uint32, SDL_static_cast(Uint8, (C))) << 16) | \
(SDL_static_cast(Uint32, SDL_static_cast(Uint8, (D))) << 24))

## SDL_ICONV_E2BIG

#define SDL_ICONV_E2BIG (size_t)-2

Output buffer was too small.

Definition at line 5896 of file SDL_stdinc.h.

## SDL_ICONV_EILSEQ

#define SDL_ICONV_EILSEQ (size_t)-3

Invalid input sequence was encountered.

Definition at line 5897 of file SDL_stdinc.h.

## SDL_ICONV_EINVAL

#define SDL_ICONV_EINVAL (size_t)-4

Incomplete input sequence was encountered.

Definition at line 5898 of file SDL_stdinc.h.

## SDL_ICONV_ERROR

#define SDL_ICONV_ERROR (size_t)-1

Generic error. Check SDL_GetError()?

Definition at line 5895 of file SDL_stdinc.h.

## SDL_iconv_utf8_locale

#define SDL_iconv_utf8_locale | ( |  | S | ) |

Value:
SDL_iconv_string("", "UTF-8", S, SDL_strlen(S)+1)
SDL_iconv_string
char * SDL_iconv_string(const char *tocode, const char *fromcode, const char *inbuf, size_t inbytesleft)
SDL_strlen
size_t SDL_strlen(const char *str)

Convert a UTF-8 string to the current locale's character encoding.

This is a helper macro that might be more clear than calling SDL_iconv_string directly. However, it double-evaluates its parameter, so do not use an expression with side-effects here.

Parameters

  S | the string to convert.

Returns
  a new string, converted to the new encoding, or NULL on error.

\threadsafety It is safe to call this macro from any thread.

Since
  This macro is available since SDL 3.2.0.

Definition at line 5949 of file SDL_stdinc.h.

## SDL_iconv_utf8_ucs2

#define SDL_iconv_utf8_ucs2 | ( |  | S | ) |

Value:
SDL_reinterpret_cast(Uint16 *, SDL_iconv_string("UCS-2", "UTF-8", S, SDL_strlen(S)+1))
Uint16
uint16_t Uint16
Definition SDL_stdinc.h:464
SDL_reinterpret_cast
#define SDL_reinterpret_cast(type, expression)
Definition SDL_stdinc.h:344

Convert a UTF-8 string to UCS-2.

This is a helper macro that might be more clear than calling SDL_iconv_string directly. However, it double-evaluates its parameter, so do not use an expression with side-effects here.

Parameters

  S | the string to convert.

Returns
  a new string, converted to the new encoding, or NULL on error.

\threadsafety It is safe to call this macro from any thread.

Since
  This macro is available since SDL 3.2.0.

Definition at line 5965 of file SDL_stdinc.h.

## SDL_iconv_utf8_ucs4

#define SDL_iconv_utf8_ucs4 | ( |  | S | ) |

Value:
SDL_reinterpret_cast(Uint32 *, SDL_iconv_string("UCS-4", "UTF-8", S, SDL_strlen(S)+1))

Convert a UTF-8 string to UCS-4.

This is a helper macro that might be more clear than calling SDL_iconv_string directly. However, it double-evaluates its parameter, so do not use an expression with side-effects here.

Parameters

  S | the string to convert.

Returns
  a new string, converted to the new encoding, or NULL on error.

\threadsafety It is safe to call this macro from any thread.

Since
  This macro is available since SDL 3.2.0.

Definition at line 5981 of file SDL_stdinc.h.

## SDL_iconv_wchar_utf8

#define SDL_iconv_wchar_utf8 | ( |  | S | ) |

Value:
SDL_iconv_string("UTF-8", "WCHAR_T", SDL_reinterpret_cast(const char *, S), (SDL_wcslen(S)+1)*sizeof(wchar_t))
SDL_wcslen
size_t SDL_wcslen(const wchar_t *wstr)

Convert a wchar_t string to UTF-8.

This is a helper macro that might be more clear than calling SDL_iconv_string directly. However, it double-evaluates its parameter, so do not use an expression with side-effects here.

Parameters

  S | the string to convert.

Returns
  a new string, converted to the new encoding, or NULL on error.

\threadsafety It is safe to call this macro from any thread.

Since
  This macro is available since SDL 3.2.0.

Definition at line 5997 of file SDL_stdinc.h.

## SDL_IN_BYTECAP

#define SDL_IN_BYTECAP | ( |  | x | ) |

Definition at line 1141 of file SDL_stdinc.h.

## SDL_INIT_INTERFACE

#define SDL_INIT_INTERFACE | ( |  | iface | ) |

Value:
do { \
SDL_zerop(iface); \
(iface)->version = sizeof(*(iface)); \
} while (0)

A macro to initialize an SDL interface.

This macro will initialize an SDL interface structure and should be called before you fill out the fields with your implementation.

You can use it like this:

SDL_IOStreamInterface iface;
SDL_INIT_INTERFACE(&iface);
// Fill in the interface function pointers with your implementation
iface.seek = ...
stream = SDL_OpenIO(&iface, NULL);
NULL
#define NULL
Definition SDL_begin_code.h:469
SDL_OpenIO
SDL_IOStream * SDL_OpenIO(const SDL_IOStreamInterface *iface, void *userdata)
SDL_INIT_INTERFACE
#define SDL_INIT_INTERFACE(iface)
Definition SDL_stdinc.h:1256
SDL_IOStreamInterface
Definition SDL_iostream.h:93
SDL_IOStreamInterface::seek
Sint64(* seek)(void *userdata, Sint64 offset, SDL_IOWhence whence)
Definition SDL_iostream.h:110

If you are using designated initializers, you can use the size of the interface as the version, e.g.

SDL_IOStreamInterface iface = {
.version = sizeof(iface),
.seek = ...
};
stream = SDL_OpenIO(&iface, NULL);

\threadsafety It is safe to call this macro from any thread.

Since
  This macro is available since SDL 3.2.0.

See also
  SDL_IOStreamInterface
  SDL_StorageInterface
  SDL_VirtualJoystickDesc

Definition at line 1256 of file SDL_stdinc.h.

#define SDL_INIT_INTERFACE(iface) \
do { \
SDL_zerop(iface); \
(iface)->version = sizeof(*(iface)); \
} while (0)

## SDL_INOUT_Z_CAP

#define SDL_INOUT_Z_CAP | ( |  | x | ) |

Definition at line 1142 of file SDL_stdinc.h.

## SDL_INVALID_UNICODE_CODEPOINT

#define SDL_INVALID_UNICODE_CODEPOINT 0xFFFD

The Unicode REPLACEMENT CHARACTER codepoint.

SDL_StepUTF8() and SDL_StepBackUTF8() report this codepoint when they encounter a UTF-8 string with encoding errors.

This tends to render as something like a question mark in most places.

Since
  This macro is available since SDL 3.2.0.

See also
  SDL_StepBackUTF8
  SDL_StepUTF8

Definition at line 3985 of file SDL_stdinc.h.

## SDL_max

#define SDL_max | ( |  | x,
|  |  | y )

Value:
(((x) > (y)) ? (x) : (y))

Return the greater of two values.

This is a helper macro that might be more clear than writing out the comparisons directly, and works with any type that can be compared with the > operator. However, it double-evaluates both its parameters, so do not use expressions with side-effects here.

Parameters

  x | the first value to compare.
  y | the second value to compare.

Returns
  the greater of x and y.

\threadsafety It is safe to call this macro from any thread.

Since
  This macro is available since SDL 3.2.0.

Definition at line 2157 of file SDL_stdinc.h.

## SDL_MAX_SINT16

#define SDL_MAX_SINT16 ((Sint16)0x7FFF) /* 32767 */

Definition at line 456 of file SDL_stdinc.h.

## SDL_MAX_SINT32

#define SDL_MAX_SINT32 ((Sint32)0x7FFFFFFF) /* 2147483647 */

Definition at line 474 of file SDL_stdinc.h.

## SDL_MAX_SINT64

#define SDL_MAX_SINT64 SDL_SINT64_C(0x7FFFFFFFFFFFFFFF) /* 9223372036854775807 */

Definition at line 494 of file SDL_stdinc.h.

## SDL_MAX_SINT8

#define SDL_MAX_SINT8 ((Sint8)0x7F) /* 127 */

Definition at line 438 of file SDL_stdinc.h.

## SDL_MAX_TIME

#define SDL_MAX_TIME SDL_MAX_SINT64

Definition at line 522 of file SDL_stdinc.h.

## SDL_MAX_UINT16

#define SDL_MAX_UINT16 ((Uint16)0xFFFF) /* 65535 */

Definition at line 465 of file SDL_stdinc.h.

## SDL_MAX_UINT32

#define SDL_MAX_UINT32 ((Uint32)0xFFFFFFFFu) /* 4294967295 */

Definition at line 483 of file SDL_stdinc.h.

## SDL_MAX_UINT64

#define SDL_MAX_UINT64 SDL_UINT64_C(0xFFFFFFFFFFFFFFFF) /* 18446744073709551615 */

Definition at line 505 of file SDL_stdinc.h.

## SDL_MAX_UINT8

#define SDL_MAX_UINT8 ((Uint8)0xFF) /* 255 */

Definition at line 447 of file SDL_stdinc.h.

## SDL_memcpy

#define SDL_memcpy memcpy

Definition at line 2512 of file SDL_stdinc.h.

## SDL_memmove

#define SDL_memmove memmove

Definition at line 2568 of file SDL_stdinc.h.

## SDL_memset

#define SDL_memset memset

Definition at line 2616 of file SDL_stdinc.h.

## SDL_min

#define SDL_min | ( |  | x,
|  |  | y )

Value:
(((x) < (y)) ? (x) : (y))

Return the lesser of two values.

This is a helper macro that might be more clear than writing out the comparisons directly, and works with any type that can be compared with the < operator. However, it double-evaluates both its parameters, so do not use expressions with side-effects here.

Parameters

  x | the first value to compare.
  y | the second value to compare.

Returns
  the lesser of x and y.

\threadsafety It is safe to call this macro from any thread.

Since
  This macro is available since SDL 3.2.0.

Definition at line 2139 of file SDL_stdinc.h.

## SDL_MIN_SINT16

#define SDL_MIN_SINT16 ((Sint16)(~0x7FFF)) /* -32768 */

Definition at line 457 of file SDL_stdinc.h.

## SDL_MIN_SINT32

#define SDL_MIN_SINT32 ((Sint32)(~0x7FFFFFFF)) /* -2147483648 */

Definition at line 475 of file SDL_stdinc.h.

## SDL_MIN_SINT64

#define SDL_MIN_SINT64 ~SDL_SINT64_C(0x7FFFFFFFFFFFFFFF) /* -9223372036854775808 */

Definition at line 495 of file SDL_stdinc.h.

## SDL_MIN_SINT8

#define SDL_MIN_SINT8 ((Sint8)(~0x7F)) /* -128 */

Definition at line 439 of file SDL_stdinc.h.

## SDL_MIN_TIME

#define SDL_MIN_TIME SDL_MIN_SINT64

Definition at line 523 of file SDL_stdinc.h.

## SDL_MIN_UINT16

#define SDL_MIN_UINT16 ((Uint16)0x0000) /* 0 */

Definition at line 466 of file SDL_stdinc.h.

## SDL_MIN_UINT32

#define SDL_MIN_UINT32 ((Uint32)0x00000000) /* 0 */

Definition at line 484 of file SDL_stdinc.h.

## SDL_MIN_UINT64

#define SDL_MIN_UINT64 SDL_UINT64_C(0x0000000000000000) /* 0 */

Definition at line 506 of file SDL_stdinc.h.

## SDL_MIN_UINT8

#define SDL_MIN_UINT8 ((Uint8)0x00) /* 0 */

Definition at line 448 of file SDL_stdinc.h.

## SDL_OUT_BYTECAP

#define SDL_OUT_BYTECAP | ( |  | x | ) |

Definition at line 1145 of file SDL_stdinc.h.

## SDL_OUT_CAP

#define SDL_OUT_CAP | ( |  | x | ) |

Definition at line 1144 of file SDL_stdinc.h.

## SDL_OUT_Z_BYTECAP

#define SDL_OUT_Z_BYTECAP | ( |  | x | ) |

Definition at line 1146 of file SDL_stdinc.h.

## SDL_OUT_Z_CAP

#define SDL_OUT_Z_CAP | ( |  | x | ) |

Definition at line 1143 of file SDL_stdinc.h.

Referenced by SDL_snprintf(), SDL_swprintf(), SDL_vsnprintf(), and SDL_vswprintf().

## SDL_PI_D

#define SDL_PI_D 3.141592653589793238462643383279502884

The value of Pi, as a double-precision floating point literal.

Since
  This macro is available since SDL 3.2.0.

See also
  SDL_PI_F pi (double)

Definition at line 4480 of file SDL_stdinc.h.

## SDL_PI_F

#define SDL_PI_F 3.141592653589793238462643383279502884F

The value of Pi, as a single-precision floating point literal.

Since
  This macro is available since SDL 3.2.0.

See also
  SDL_PI_D pi (float)

Definition at line 4492 of file SDL_stdinc.h.

## SDL_PRILL_PREFIX

#define SDL_PRILL_PREFIX "ll"

Definition at line 808 of file SDL_stdinc.h.

## SDL_PRILLd

#define SDL_PRILLd SDL_PRILL_PREFIX "d"

Definition at line 811 of file SDL_stdinc.h.

## SDL_PRILLu

#define SDL_PRILLu SDL_PRILL_PREFIX "u"

Definition at line 814 of file SDL_stdinc.h.

## SDL_PRILLX

#define SDL_PRILLX SDL_PRILL_PREFIX "X"

Definition at line 820 of file SDL_stdinc.h.

## SDL_PRILLx

#define SDL_PRILLx SDL_PRILL_PREFIX "x"

Definition at line 817 of file SDL_stdinc.h.

## SDL_PRINTF_FORMAT_STRING

#define SDL_PRINTF_FORMAT_STRING

Definition at line 1147 of file SDL_stdinc.h.

Referenced by SDL_asprintf(), SDL_IOprintf(), SDL_IOvprintf(), SDL_Log(), SDL_LogCritical(), SDL_LogDebug(), SDL_LogError(), SDL_LogInfo(), SDL_LogMessage(), SDL_LogMessageV(), SDL_LogTrace(), SDL_LogVerbose(), SDL_LogWarn(), SDL_RenderDebugTextFormat(), SDL_SetError(), SDL_SetErrorV(), SDL_snprintf(), SDL_swprintf(), SDL_vasprintf(), SDL_vsnprintf(), SDL_vswprintf(), SDLTest_Assert(), SDLTest_AssertCheck(), SDLTest_AssertPass(), SDLTest_Log(), SDLTest_LogError(), SDLTest_LogMessage(), and SDLTest_TextWindowAddText().

## SDL_PRINTF_VARARG_FUNC

#define SDL_PRINTF_VARARG_FUNC | ( |  | fmtargnumber | ) |

Definition at line 1158 of file SDL_stdinc.h.

Referenced by SDL_asprintf(), SDL_IOprintf(), SDL_Log(), SDL_LogCritical(), SDL_LogDebug(), SDL_LogError(), SDL_LogInfo(), SDL_LogMessage(), SDL_LogTrace(), SDL_LogVerbose(), SDL_LogWarn(), SDL_RenderDebugTextFormat(), SDL_SetError(), SDL_snprintf(), SDLTest_Assert(), SDLTest_AssertCheck(), SDLTest_AssertPass(), SDLTest_Log(), SDLTest_LogError(), and SDLTest_TextWindowAddText().

## SDL_PRINTF_VARARG_FUNCV

#define SDL_PRINTF_VARARG_FUNCV | ( |  | fmtargnumber | ) |

Definition at line 1159 of file SDL_stdinc.h.

Referenced by SDL_IOvprintf(), SDL_LogMessageV(), SDL_SetErrorV(), SDL_vasprintf(), and SDL_vsnprintf().

## SDL_PRIs32

#define SDL_PRIs32 "d"

Definition at line 777 of file SDL_stdinc.h.

## SDL_PRIs64

#define SDL_PRIs64 "lld"

Definition at line 737 of file SDL_stdinc.h.

## SDL_PRIu32

#define SDL_PRIu32 "u"

Definition at line 784 of file SDL_stdinc.h.

## SDL_PRIu64

#define SDL_PRIu64 "llu"

Definition at line 748 of file SDL_stdinc.h.

## SDL_PRIX32

#define SDL_PRIX32 "X"

Definition at line 798 of file SDL_stdinc.h.

## SDL_PRIx32

#define SDL_PRIx32 "x"

Definition at line 791 of file SDL_stdinc.h.

## SDL_PRIX64

#define SDL_PRIX64 "llX"

Definition at line 770 of file SDL_stdinc.h.

## SDL_PRIx64

#define SDL_PRIx64 "llx"

Definition at line 759 of file SDL_stdinc.h.

## SDL_reinterpret_cast

#define SDL_reinterpret_cast | ( |  | type,
|  |  | expression )

Value:
((type)(expression))

Definition at line 344 of file SDL_stdinc.h.

## SDL_SCANF_FORMAT_STRING

#define SDL_SCANF_FORMAT_STRING

Definition at line 1148 of file SDL_stdinc.h.

Referenced by SDL_sscanf(), and SDL_vsscanf().

## SDL_SCANF_VARARG_FUNC

#define SDL_SCANF_VARARG_FUNC | ( |  | fmtargnumber | ) |

Definition at line 1160 of file SDL_stdinc.h.

Referenced by SDL_sscanf().

## SDL_SCANF_VARARG_FUNCV

#define SDL_SCANF_VARARG_FUNCV | ( |  | fmtargnumber | ) |

Definition at line 1161 of file SDL_stdinc.h.

Referenced by SDL_vsscanf().

## SDL_SINT64_C

#define SDL_SINT64_C | ( |  | c | ) |

Value:
c ## LL

Definition at line 409 of file SDL_stdinc.h.

## SDL_SIZE_MAX

#define SDL_SIZE_MAX ((size_t) -1)

Definition at line 184 of file SDL_stdinc.h.

Referenced by SDL_size_add_check_overflow(), and SDL_size_mul_check_overflow().

## SDL_stack_alloc

#define SDL_stack_alloc | ( |  | type,
|  |  | count )

Value:
(type*)alloca(sizeof(type)*(count))
alloca
void * alloca(size_t)

Definition at line 1309 of file SDL_stdinc.h.

## SDL_stack_free

#define SDL_stack_free | ( |  | data | ) |

Value:
((void)(data))

Definition at line 1310 of file SDL_stdinc.h.

## SDL_static_cast

#define SDL_static_cast | ( |  | type,
|  |  | expression )

Value:
((type)(expression))

Definition at line 345 of file SDL_stdinc.h.

Referenced by SDL_RectToFRect(), SDL_Swap16(), SDL_Swap32(), and SDL_Swap64().

## SDL_STRINGIFY_ARG

#define SDL_STRINGIFY_ARG | ( |  | arg | ) |

Value:
#arg

Macro useful for building other macros with strings in them.

Parameters

  arg | the text to turn into a string literal.

Since
  This macro is available since SDL 3.2.0.

Definition at line 261 of file SDL_stdinc.h.

## SDL_UINT64_C

#define SDL_UINT64_C | ( |  | c | ) |

Value:
c ## ULL

Definition at line 421 of file SDL_stdinc.h.

## SDL_WPRINTF_VARARG_FUNC

#define SDL_WPRINTF_VARARG_FUNC | ( |  | fmtargnumber | ) |

Definition at line 1162 of file SDL_stdinc.h.

Referenced by SDL_swprintf().

## SDL_WPRINTF_VARARG_FUNCV

#define SDL_WPRINTF_VARARG_FUNCV | ( |  | fmtargnumber | ) |

Definition at line 1163 of file SDL_stdinc.h.

Referenced by SDL_vswprintf().

## SDL_zero

#define SDL_zero | ( |  | x | ) |

Value:
SDL_memset(&(x), 0, sizeof((x)))
SDL_memset
#define SDL_memset
Definition SDL_stdinc.h:2616

Clear an object's memory to zero.

This is wrapper over SDL_memset that handles calculating the object size, so there's no chance of copy/paste errors, and the code is cleaner.

This requires an object, not a pointer to an object, nor an array.

Parameters

  x | the object to clear.

\threadsafety It is safe to call this macro from any thread.

Since
  This macro is available since SDL 3.2.0.

See also
  SDL_zerop
  SDL_zeroa

Definition at line 2636 of file SDL_stdinc.h.

## SDL_zeroa

#define SDL_zeroa | ( |  | x | ) |

Value:
SDL_memset((x), 0, sizeof((x)))

Clear an array's memory to zero.

This is wrapper over SDL_memset that handles calculating the array size, so there's no chance of copy/paste errors, and the code is cleaner.

This requires an array, not an object, nor a pointer to an object.

Parameters

  x | an array to clear.

\threadsafety It is safe to call this macro from any thread.

Since
  This macro is available since SDL 3.2.0.

See also
  SDL_zero
  SDL_zerop

Definition at line 2674 of file SDL_stdinc.h.

## SDL_zerop

#define SDL_zerop | ( |  | x | ) |

Value:
SDL_memset((x), 0, sizeof(*(x)))

Clear an object's memory to zero, using a pointer.

This is wrapper over SDL_memset that handles calculating the object size, so there's no chance of copy/paste errors, and the code is cleaner.

This requires a pointer to an object, not an object itself, nor an array.

Parameters

  x | a pointer to the object to clear.

\threadsafety It is safe to call this macro from any thread.

Since
  This macro is available since SDL 3.2.0.

See also
  SDL_zero
  SDL_zeroa

Definition at line 2655 of file SDL_stdinc.h.

## true

#define true 1

Definition at line 101 of file SDL_stdinc.h.

Referenced by SDL_PointInRect(), SDL_PointInRectFloat(), SDL_RectEmpty(), SDL_RectEmptyFloat(), SDL_RectsEqual(), and SDL_RectsEqualEpsilon().

## Typedef Documentation

## SDL_calloc_func

typedef void *(* SDL_calloc_func) (size_t nmemb, size_t size)

A callback used to implement SDL_calloc().

SDL will always ensure that the passed nmemb and size are both greater than 0.

Parameters

  nmemb | the number of elements in the array.
  size | the size of each element of the array.

Returns
  a pointer to the allocated array, or NULL if allocation failed.

\threadsafety It should be safe to call this callback from any thread.

Since
  This datatype is available since SDL 3.2.0.

See also
  SDL_calloc
  SDL_GetOriginalMemoryFunctions
  SDL_GetMemoryFunctions
  SDL_SetMemoryFunctions

Definition at line 1467 of file SDL_stdinc.h.

## SDL_CompareCallback

typedef int(* SDL_CompareCallback) (const void *a, const void *b)

A callback used with SDL sorting and binary search functions.

Parameters

  a | a pointer to the first element being compared.
  b | a pointer to the second element being compared.

Returns
  -1 if a should be sorted before b, 1 if b should be sorted before a, 0 if they are equal. If two elements are equal, their order in the sorted array is undefined.

Since
  This callback is available since SDL 3.2.0.

See also
  SDL_bsearch
  SDL_qsort

Definition at line 1885 of file SDL_stdinc.h.

## SDL_CompareCallback_r

typedef int(* SDL_CompareCallback_r) (void *userdata, const void *a, const void *b)

A callback used with SDL sorting and binary search functions.

Parameters

  userdata | the userdata pointer passed to the sort function.
  a | a pointer to the first element being compared.
  b | a pointer to the second element being compared.

Returns
  -1 if a should be sorted before b, 1 if b should be sorted before a, 0 if they are equal. If two elements are equal, their order in the sorted array is undefined.

Since
  This callback is available since SDL 3.2.0.

See also
  SDL_qsort_r
  SDL_bsearch_r

Definition at line 1998 of file SDL_stdinc.h.

## SDL_Environment

typedef struct SDL_Environment SDL_Environment

A thread-safe set of environment variables

Since
  This struct is available since SDL 3.2.0.

See also
  SDL_GetEnvironment
  SDL_CreateEnvironment
  SDL_GetEnvironmentVariable
  SDL_GetEnvironmentVariables
  SDL_SetEnvironmentVariable
  SDL_UnsetEnvironmentVariable
  SDL_DestroyEnvironment

Definition at line 1650 of file SDL_stdinc.h.

## SDL_free_func

typedef void(* SDL_free_func) (void *mem)

A callback used to implement SDL_free().

SDL will always ensure that the passed mem is a non-NULL pointer.

Parameters

  mem | a pointer to allocated memory.

\threadsafety It should be safe to call this callback from any thread.

Since
  This datatype is available since SDL 3.2.0.

See also
  SDL_free
  SDL_GetOriginalMemoryFunctions
  SDL_GetMemoryFunctions
  SDL_SetMemoryFunctions

Definition at line 1506 of file SDL_stdinc.h.

## SDL_FunctionPointer

typedef void(* SDL_FunctionPointer) (void)

Definition at line 6177 of file SDL_stdinc.h.

## SDL_iconv_t

typedef struct SDL_iconv_data_t* SDL_iconv_t

An opaque handle representing string encoding conversion state.

Since
  This datatype is available since SDL 3.2.0.

See also
  SDL_iconv_open

Definition at line 5815 of file SDL_stdinc.h.

## SDL_malloc_func

typedef void *(* SDL_malloc_func) (size_t size)

A callback used to implement SDL_malloc().

SDL will always ensure that the passed size is greater than 0.

Parameters

  size | the size to allocate.

Returns
  a pointer to the allocated memory, or NULL if allocation failed.

\threadsafety It should be safe to call this callback from any thread.

Since
  This datatype is available since SDL 3.2.0.

See also
  SDL_malloc
  SDL_GetOriginalMemoryFunctions
  SDL_GetMemoryFunctions
  SDL_SetMemoryFunctions

Definition at line 1446 of file SDL_stdinc.h.

## SDL_realloc_func

typedef void *(* SDL_realloc_func) (void *mem, size_t size)

A callback used to implement SDL_realloc().

SDL will always ensure that the passed size is greater than 0.

Parameters

  mem | a pointer to allocated memory to reallocate, or NULL.
  size | the new size of the memory.

Returns
  a pointer to the newly allocated memory, or NULL if allocation failed.

\threadsafety It should be safe to call this callback from any thread.

Since
  This datatype is available since SDL 3.2.0.

See also
  SDL_realloc
  SDL_GetOriginalMemoryFunctions
  SDL_GetMemoryFunctions
  SDL_SetMemoryFunctions

Definition at line 1488 of file SDL_stdinc.h.

## SDL_Time

typedef Sint64 SDL_Time

SDL times are signed, 64-bit integers representing nanoseconds since the Unix epoch (Jan 1, 1970).

They can be converted between POSIX time_t values with SDL_NS_TO_SECONDS() and SDL_SECONDS_TO_NS(), and between Windows FILETIME values with SDL_TimeToWindows() and SDL_TimeFromWindows().

Since
  This datatype is available since SDL 3.2.0.

See also
  SDL_MAX_SINT64
  SDL_MIN_SINT64

Definition at line 521 of file SDL_stdinc.h.

## Sint16

typedef int16_t Sint16

A signed 16-bit integer type.

Since
  This macro is available since SDL 3.2.0.

Definition at line 455 of file SDL_stdinc.h.

## Sint32

typedef int32_t Sint32

A signed 32-bit integer type.

Since
  This macro is available since SDL 3.2.0.

Definition at line 473 of file SDL_stdinc.h.

## Sint64

typedef int64_t Sint64

A signed 64-bit integer type.

Since
  This macro is available since SDL 3.2.0.

See also
  SDL_SINT64_C

Definition at line 493 of file SDL_stdinc.h.

## Sint8

typedef int8_t Sint8

A signed 8-bit integer type.

Since
  This macro is available since SDL 3.2.0.

Definition at line 437 of file SDL_stdinc.h.

## Uint16

typedef uint16_t Uint16

An unsigned 16-bit integer type.

Since
  This macro is available since SDL 3.2.0.

Definition at line 464 of file SDL_stdinc.h.

## Uint32

typedef uint32_t Uint32

An unsigned 32-bit integer type.

Since
  This macro is available since SDL 3.2.0.

Definition at line 482 of file SDL_stdinc.h.

## Uint64

typedef uint64_t Uint64

An unsigned 64-bit integer type.

Since
  This macro is available since SDL 3.2.0.

See also
  SDL_UINT64_C

Definition at line 504 of file SDL_stdinc.h.

## Uint8

typedef uint8_t Uint8

An unsigned 8-bit integer type.

Since
  This macro is available since SDL 3.2.0.

Definition at line 446 of file SDL_stdinc.h.

## Function Documentation

## alloca()

void * alloca | ( | size_t |  | ) |

## SDL_abs()

int SDL_abs | ( | int | x | ) |

extern

Compute the absolute value of x.

Parameters

  x | an integer value.

Returns
  the absolute value of x.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

References SDL_abs().

Referenced by SDL_abs().

## SDL_acos()

double SDL_acos | ( | double | x | ) |

extern

Compute the arc cosine of x.

The definition of y = acos(x) is x = cos(y).

Domain: -1 <= x <= 1

Range: 0 <= y <= Pi

This function operates on double-precision floating point values, use SDL_acosf for single-precision floats.

This function may use a different approximation across different versions, platforms and configurations. i.e, it can return a different value given the same input on different machines or operating systems, or if SDL is updated.

Parameters

  x | floating point value.

Returns
  arc cosine of x, in radians.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_acosf
  SDL_asin
  SDL_cos

## SDL_acosf()

float SDL_acosf | ( | float | x | ) |

extern

Compute the arc cosine of x.

The definition of y = acos(x) is x = cos(y).

Domain: -1 <= x <= 1

Range: 0 <= y <= Pi

This function operates on single-precision floating point values, use SDL_acos for double-precision floats.

This function may use a different approximation across different versions, platforms and configurations. i.e, it can return a different value given the same input on different machines or operating systems, or if SDL is updated.

Parameters

  x | floating point value.

Returns
  arc cosine of x, in radians.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_acos
  SDL_asinf
  SDL_cosf

## SDL_aligned_alloc()

SDL_MALLOC void * SDL_aligned_alloc | ( | size_t | alignment,
|  | size_t | size )

extern

Allocate memory aligned to a specific alignment.

The memory returned by this function must be freed with SDL_aligned_free(), not SDL_free().

If alignment is less than the size of void *, it will be increased to match that.

The returned memory address will be a multiple of the alignment value, and the size of the memory allocated will be a multiple of the alignment value.

Parameters

  alignment | the alignment of the memory.
  size | the size to allocate.

Returns
  a pointer to the aligned memory, or NULL if allocation failed.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_aligned_free

References SDL_aligned_alloc(), SDL_MALLOC, and size.

Referenced by SDL_aligned_alloc().

## SDL_aligned_free()

void SDL_aligned_free | ( | void * | mem | ) |

extern

Free memory allocated by SDL_aligned_alloc().

The pointer is no longer valid after this call and cannot be dereferenced anymore.

If mem is NULL, this function does nothing.

Parameters

  mem | a pointer previously returned by SDL_aligned_alloc(), or NULL.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_aligned_alloc

References SDL_aligned_free().

Referenced by SDL_aligned_free().

## SDL_ALLOC_SIZE()

SDL_ALLOC_SIZE | ( | 2 |  | ) |

extern

Change the size of allocated memory.

The memory returned by this function must be freed with SDL_free().

If size is 0, it will be set to 1. Note that this is unlike some other C runtime realloc implementations, which may treat realloc(mem, 0) the same way as free(mem).

If mem is NULL, the behavior of this function is equivalent to SDL_malloc(). Otherwise, the function can have one of three possible outcomes:

- If it returns the same pointer as mem, it means that mem was resized in place without freeing.
- If it returns a different non-NULL pointer, it means that mem was freed and cannot be dereferenced anymore.
- If it returns NULL (indicating failure), then mem will remain valid and must still be freed with SDL_free().

If the allocation is successfully resized, the returned pointer is guaranteed to be aligned to either the fundamental alignment (alignof(max_align_t) in C11 and later) or 2 * sizeof(void *), whichever is smaller.

Parameters

  mem | a pointer to allocated memory to reallocate, or NULL.
  size | the new size of the memory.

Returns
  a pointer to the newly allocated memory, or NULL if allocation failed.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_free
  SDL_malloc
  SDL_calloc

References SDL_ALLOC_SIZE, and size.

## SDL_ALLOC_SIZE2()

SDL_MALLOC SDL_ALLOC_SIZE2 | ( | 1 | ,
|  | 2 | )

extern

Allocate a zero-initialized array.

The memory returned by this function must be freed with SDL_free().

If either of nmemb or size is 0, they will both be set to 1.

If the allocation is successful, the returned pointer is guaranteed to be aligned to either the fundamental alignment (alignof(max_align_t) in C11 and later) or 2 * sizeof(void *), whichever is smaller.

Parameters

  nmemb | the number of elements in the array.
  size | the size of each element of the array.

Returns
  a pointer to the allocated array, or NULL if allocation failed.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_free
  SDL_malloc
  SDL_realloc

References SDL_MALLOC, and size.

## SDL_asin()

double SDL_asin | ( | double | x | ) |

extern

Compute the arc sine of x.

The definition of y = asin(x) is x = sin(y).

Domain: -1 <= x <= 1

Range: -Pi/2 <= y <= Pi/2

This function operates on double-precision floating point values, use SDL_asinf for single-precision floats.

This function may use a different approximation across different versions, platforms and configurations. i.e, it can return a different value given the same input on different machines or operating systems, or if SDL is updated.

Parameters

  x | floating point value.

Returns
  arc sine of x, in radians.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_asinf
  SDL_acos
  SDL_sin

## SDL_asinf()

float SDL_asinf | ( | float | x | ) |

extern

Compute the arc sine of x.

The definition of y = asin(x) is x = sin(y).

Domain: -1 <= x <= 1

Range: -Pi/2 <= y <= Pi/2

This function operates on single-precision floating point values, use SDL_asin for double-precision floats.

This function may use a different approximation across different versions, platforms and configurations. i.e, it can return a different value given the same input on different machines or operating systems, or if SDL is updated.

Parameters

  x | floating point value.

Returns
  arc sine of x, in radians.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_asin
  SDL_acosf
  SDL_sinf

## SDL_asprintf()

int SDL_asprintf | ( | char ** | strp,
|  | SDL_PRINTF_FORMAT_STRING const char * | fmt,
|  |  | ... )

extern

This works exactly like asprintf() but doesn't require access to a C runtime.

Functions identically to SDL_snprintf(), except it allocates a buffer large enough to hold the output string on behalf of the caller.

On success, this function returns the number of bytes (not characters) comprising the output string, not counting the null-terminator character, and sets *strp to the newly-allocated string.

On error, this function returns a negative number, and the value of *strp is undefined.

The returned string is owned by the caller, and should be passed to SDL_free when no longer needed.

Parameters

  strp | on output, is set to the new string. Must not be NULL.
  fmt | a printf-style format string. Must not be NULL.
  ... | a list of values to be used with the format string.

Returns
  the number of bytes in the newly-allocated string, not counting the null-terminator char, or a negative value on error.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

References SDL_asprintf(), SDL_PRINTF_FORMAT_STRING, and SDL_PRINTF_VARARG_FUNC.

Referenced by SDL_asprintf().

## SDL_atan()

double SDL_atan | ( | double | x | ) |

extern

Compute the arc tangent of x.

The definition of y = atan(x) is x = tan(y).

Domain: -INF <= x <= INF

Range: -Pi/2 <= y <= Pi/2

This function operates on double-precision floating point values, use SDL_atanf for single-precision floats.

To calculate the arc tangent of y / x, use SDL_atan2.

This function may use a different approximation across different versions, platforms and configurations. i.e, it can return a different value given the same input on different machines or operating systems, or if SDL is updated.

Parameters

  x | floating point value.

Returns
  arc tangent of of x in radians, or 0 if x = 0.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_atanf
  SDL_atan2
  SDL_tan

## SDL_atan2()

double SDL_atan2 | ( | double | y,
|  | double | x )

extern

Compute the arc tangent of y / x, using the signs of x and y to adjust the result's quadrant.

The definition of z = atan2(x, y) is y = x tan(z), where the quadrant of z is determined based on the signs of x and y.

Domain: -INF <= x <= INF, -INF <= y <= INF

Range: -Pi <= y <= Pi

This function operates on double-precision floating point values, use SDL_atan2f for single-precision floats.

To calculate the arc tangent of a single value, use SDL_atan.

This function may use a different approximation across different versions, platforms and configurations. i.e, it can return a different value given the same input on different machines or operating systems, or if SDL is updated.

Parameters

  y | floating point value of the numerator (y coordinate).
  x | floating point value of the denominator (x coordinate).

Returns
  arc tangent of of y / x in radians, or, if x = 0, either -Pi/2, 0, or Pi/2, depending on the value of y.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_atan2f
  SDL_atan
  SDL_tan

## SDL_atan2f()

float SDL_atan2f | ( | float | y,
|  | float | x )

extern

Compute the arc tangent of y / x, using the signs of x and y to adjust the result's quadrant.

The definition of z = atan2(x, y) is y = x tan(z), where the quadrant of z is determined based on the signs of x and y.

Domain: -INF <= x <= INF, -INF <= y <= INF

Range: -Pi <= y <= Pi

This function operates on single-precision floating point values, use SDL_atan2 for double-precision floats.

To calculate the arc tangent of a single value, use SDL_atanf.

This function may use a different approximation across different versions, platforms and configurations. i.e, it can return a different value given the same input on different machines or operating systems, or if SDL is updated.

Parameters

  y | floating point value of the numerator (y coordinate).
  x | floating point value of the denominator (x coordinate).

Returns
  arc tangent of of y / x in radians, or, if x = 0, either -Pi/2, 0, or Pi/2, depending on the value of y.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_atan2
  SDL_atan
  SDL_tan

## SDL_atanf()

float SDL_atanf | ( | float | x | ) |

extern

Compute the arc tangent of x.

The definition of y = atan(x) is x = tan(y).

Domain: -INF <= x <= INF

Range: -Pi/2 <= y <= Pi/2

This function operates on single-precision floating point values, use SDL_atan for dboule-precision floats.

To calculate the arc tangent of y / x, use SDL_atan2f.

This function may use a different approximation across different versions, platforms and configurations. i.e, it can return a different value given the same input on different machines or operating systems, or if SDL is updated.

Parameters

  x | floating point value.

Returns
  arc tangent of of x in radians, or 0 if x = 0.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_atan
  SDL_atan2f
  SDL_tanf

## SDL_atof()

double SDL_atof | ( | const char * | str | ) |

extern

Parse a double from a string.

The result of calling SDL_atof(str) is equivalent to SDL_strtod(str, NULL).

Parameters

  str | The null-terminated string to read. Must not be NULL.

Returns
  the parsed double.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_atoi
  SDL_strtol
  SDL_strtoul
  SDL_strtoll
  SDL_strtoull
  SDL_strtod

## SDL_atoi()

int SDL_atoi | ( | const char * | str | ) |

extern

Parse an int from a string.

The result of calling SDL_atoi(str) is equivalent to (int)SDL_strtol(str, NULL, 10).

Parameters

  str | The null-terminated string to read. Must not be NULL.

Returns
  the parsed int.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_atof
  SDL_strtol
  SDL_strtoul
  SDL_strtoll
  SDL_strtoull
  SDL_strtod
  SDL_itoa

## SDL_bsearch()

void * SDL_bsearch | ( | const void * | key,
|  | const void * | base,
|  | size_t | nmemb,
|  | size_t | size,
|  | SDL_CompareCallback | compare )

extern

Perform a binary search on a previously sorted array.

For example:

typedef struct {
int key;
const char *string;
} data;
int SDLCALL compare(const void *a, const void *b)
{
const data *A = (const data *)a;
const data *B = (const data *)b;
if (A->n < B->n) {
return -1;
} else if (B->n < A->n) {
return 1;
} else {
return 0;
}
}
data values[] = {
{ 1, "first" }, { 2, "second" }, { 3, "third" }
};
data key = { 2, NULL };
data *result = SDL_bsearch(&key, values, SDL_arraysize(values), sizeof(values[0]), compare);
SDL_arraysize
#define SDL_arraysize(array)
Definition SDL_stdinc.h:252
SDL_bsearch
void * SDL_bsearch(const void *key, const void *base, size_t nmemb, size_t size, SDL_CompareCallback compare)

Parameters

  key | a pointer to a key equal to the element being searched for.
  base | a pointer to the start of the array.
  nmemb | the number of elements in the array.
  size | the size of the elements in the array.
  compare | a function used to compare elements in the array.

Returns
  a pointer to the matching element in the array, or NULL if not found.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_bsearch_r
  SDL_qsort

References SDL_bsearch(), and size.

Referenced by SDL_bsearch().

## SDL_bsearch_r()

void * SDL_bsearch_r | ( | const void * | key,
|  | const void * | base,
|  | size_t | nmemb,
|  | size_t | size,
|  | SDL_CompareCallback_r | compare,
|  | void * | userdata )

extern

Perform a binary search on a previously sorted array, passing a userdata pointer to the compare function.

For example:

typedef enum {
sort_increasing,
sort_decreasing,
} sort_method;
typedef struct {
int key;
const char *string;
} data;
int SDLCALL compare(const void *userdata, const void *a, const void *b)
{
sort_method method = (sort_method)(uintptr_t)userdata;
const data *A = (const data *)a;
const data *B = (const data *)b;
if (A->key < B->key) {
return (method == sort_increasing) ? -1 : 1;
} else if (B->key < A->key) {
return (method == sort_increasing) ? 1 : -1;
} else {
return 0;
}
}
data values[] = {
{ 1, "first" }, { 2, "second" }, { 3, "third" }
};
data key = { 2, NULL };
data *result = SDL_bsearch_r(&key, values, SDL_arraysize(values), sizeof(values[0]), compare, (const void *)(uintptr_t)sort_increasing);
SDL_bsearch_r
void * SDL_bsearch_r(const void *key, const void *base, size_t nmemb, size_t size, SDL_CompareCallback_r compare, void *userdata)

Parameters

  key | a pointer to a key equal to the element being searched for.
  base | a pointer to the start of the array.
  nmemb | the number of elements in the array.
  size | the size of the elements in the array.
  compare | a function used to compare elements in the array.
  userdata | a pointer to pass to the compare function.

Returns
  a pointer to the matching element in the array, or NULL if not found.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_bsearch
  SDL_qsort_r

References SDL_bsearch_r(), and size.

Referenced by SDL_bsearch_r().

## SDL_ceil()

double SDL_ceil | ( | double | x | ) |

extern

Compute the ceiling of x.

The ceiling of x is the smallest integer y such that y >= x, i.e x rounded up to the nearest integer.

Domain: -INF <= x <= INF

Range: -INF <= y <= INF, y integer

This function operates on double-precision floating point values, use SDL_ceilf for single-precision floats.

Parameters

  x | floating point value.

Returns
  the ceiling of x.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_ceilf
  SDL_floor
  SDL_trunc
  SDL_round
  SDL_lround

## SDL_ceilf()

float SDL_ceilf | ( | float | x | ) |

extern

Compute the ceiling of x.

The ceiling of x is the smallest integer y such that y >= x, i.e x rounded up to the nearest integer.

Domain: -INF <= x <= INF

Range: -INF <= y <= INF, y integer

This function operates on single-precision floating point values, use SDL_ceil for double-precision floats.

Parameters

  x | floating point value.

Returns
  the ceiling of x.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_ceil
  SDL_floorf
  SDL_truncf
  SDL_roundf
  SDL_lroundf

## SDL_copysign()

double SDL_copysign | ( | double | x,
|  | double | y )

extern

Copy the sign of one floating-point value to another.

The definition of copysign is that copysign(x, y) = abs(x) * sign(y).

Domain: -INF <= x <= INF, -INF <= y <= f

Range: -INF <= z <= INF

This function operates on double-precision floating point values, use SDL_copysignf for single-precision floats.

Parameters

  x | floating point value to use as the magnitude.
  y | floating point value to use as the sign.

Returns
  the floating point value with the sign of y and the magnitude of x.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_copysignf
  SDL_fabs

## SDL_copysignf()

float SDL_copysignf | ( | float | x,
|  | float | y )

extern

Copy the sign of one floating-point value to another.

The definition of copysign is that copysign(x, y) = abs(x) * sign(y).

Domain: -INF <= x <= INF, -INF <= y <= f

Range: -INF <= z <= INF

This function operates on single-precision floating point values, use SDL_copysign for double-precision floats.

Parameters

  x | floating point value to use as the magnitude.
  y | floating point value to use as the sign.

Returns
  the floating point value with the sign of y and the magnitude of x.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_copysign
  SDL_fabsf

## SDL_cos()

double SDL_cos | ( | double | x | ) |

extern

Compute the cosine of x.

Domain: -INF <= x <= INF

Range: -1 <= y <= 1

This function operates on double-precision floating point values, use SDL_cosf for single-precision floats.

This function may use a different approximation across different versions, platforms and configurations. i.e, it can return a different value given the same input on different machines or operating systems, or if SDL is updated.

Parameters

  x | floating point value, in radians.

Returns
  cosine of x.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_cosf
  SDL_acos
  SDL_sin

## SDL_cosf()

float SDL_cosf | ( | float | x | ) |

extern

Compute the cosine of x.

Domain: -INF <= x <= INF

Range: -1 <= y <= 1

This function operates on single-precision floating point values, use SDL_cos for double-precision floats.

This function may use a different approximation across different versions, platforms and configurations. i.e, it can return a different value given the same input on different machines or operating systems, or if SDL is updated.

Parameters

  x | floating point value, in radians.

Returns
  cosine of x.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_cos
  SDL_acosf
  SDL_sinf

## SDL_crc16()

Uint16 SDL_crc16 | ( | Uint16 | crc,
|  | const void * | data,
|  | size_t | len )

extern

Calculate a CRC-16 value.

https://en.wikipedia.org/wiki/Cyclic_redundancy_check

This function can be called multiple times, to stream data to be checksummed in blocks. Each call must provide the previous CRC-16 return value to be updated with the next block. The first call to this function for a set of blocks should pass in a zero CRC value.

Parameters

  crc | the current checksum for this data set, or 0 for a new data set.
  data | a new block of data to add to the checksum.
  len | the size, in bytes, of the new block of data.

Returns
  a CRC-16 checksum value of all blocks in the data set.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

## SDL_crc32()

Uint32 SDL_crc32 | ( | Uint32 | crc,
|  | const void * | data,
|  | size_t | len )

extern

Calculate a CRC-32 value.

https://en.wikipedia.org/wiki/Cyclic_redundancy_check

This function can be called multiple times, to stream data to be checksummed in blocks. Each call must provide the previous CRC-32 return value to be updated with the next block. The first call to this function for a set of blocks should pass in a zero CRC value.

Parameters

  crc | the current checksum for this data set, or 0 for a new data set.
  data | a new block of data to add to the checksum.
  len | the size, in bytes, of the new block of data.

Returns
  a CRC-32 checksum value of all blocks in the data set.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

## SDL_CreateEnvironment()

SDL_Environment * SDL_CreateEnvironment | ( | bool | populated | ) |

extern

Create a set of environment variables

Parameters

  populated | true to initialize it from the C runtime environment, false to create an empty environment.

Returns
  a pointer to the new environment or NULL on failure; call SDL_GetError() for more information.

\threadsafety If populated is false, it is safe to call this function from any thread, otherwise it is safe if no other threads are calling setenv() or unsetenv()

Since
  This function is available since SDL 3.2.0.

See also
  SDL_GetEnvironmentVariable
  SDL_GetEnvironmentVariables
  SDL_SetEnvironmentVariable
  SDL_UnsetEnvironmentVariable
  SDL_DestroyEnvironment

References SDL_CreateEnvironment().

Referenced by SDL_CreateEnvironment().

## SDL_DestroyEnvironment()

void SDL_DestroyEnvironment | ( | SDL_Environment * | env | ) |

extern

Destroy a set of environment variables.

Parameters

  env | the environment to destroy.

\threadsafety It is safe to call this function from any thread, as long as the environment is no longer in use.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_CreateEnvironment

References SDL_DestroyEnvironment().

Referenced by SDL_DestroyEnvironment().

## SDL_exp()

double SDL_exp | ( | double | x | ) |

extern

Compute the exponential of x.

The definition of y = exp(x) is y = e^x, where e is the base of the natural logarithm. The inverse is the natural logarithm, SDL_log.

Domain: -INF <= x <= INF

Range: 0 <= y <= INF

The output will overflow if exp(x) is too large to be represented.

This function operates on double-precision floating point values, use SDL_expf for single-precision floats.

This function may use a different approximation across different versions, platforms and configurations. i.e, it can return a different value given the same input on different machines or operating systems, or if SDL is updated.

Parameters

  x | floating point value.

Returns
  value of e^x.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_expf
  SDL_log

## SDL_expf()

float SDL_expf | ( | float | x | ) |

extern

Compute the exponential of x.

The definition of y = exp(x) is y = e^x, where e is the base of the natural logarithm. The inverse is the natural logarithm, SDL_logf.

Domain: -INF <= x <= INF

Range: 0 <= y <= INF

The output will overflow if exp(x) is too large to be represented.

This function operates on single-precision floating point values, use SDL_exp for double-precision floats.

This function may use a different approximation across different versions, platforms and configurations. i.e, it can return a different value given the same input on different machines or operating systems, or if SDL is updated.

Parameters

  x | floating point value.

Returns
  value of e^x.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_exp
  SDL_logf

## SDL_fabs()

double SDL_fabs | ( | double | x | ) |

extern

Compute the absolute value of x

Domain: -INF <= x <= INF

Range: 0 <= y <= INF

This function operates on double-precision floating point values, use SDL_fabsf for single-precision floats.

Parameters

  x | floating point value to use as the magnitude.

Returns
  the absolute value of x.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_fabsf

## SDL_fabsf()

float SDL_fabsf | ( | float | x | ) |

extern

Compute the absolute value of x

Domain: -INF <= x <= INF

Range: 0 <= y <= INF

This function operates on single-precision floating point values, use SDL_fabs for double-precision floats.

Parameters

  x | floating point value to use as the magnitude.

Returns
  the absolute value of x.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_fabs

Referenced by SDL_RectsEqualEpsilon().

## SDL_floor()

double SDL_floor | ( | double | x | ) |

extern

Compute the floor of x.

The floor of x is the largest integer y such that y <= x, i.e x rounded down to the nearest integer.

Domain: -INF <= x <= INF

Range: -INF <= y <= INF, y integer

This function operates on double-precision floating point values, use SDL_floorf for single-precision floats.

Parameters

  x | floating point value.

Returns
  the floor of x.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_floorf
  SDL_ceil
  SDL_trunc
  SDL_round
  SDL_lround

## SDL_floorf()

float SDL_floorf | ( | float | x | ) |

extern

Compute the floor of x.

The floor of x is the largest integer y such that y <= x, i.e x rounded down to the nearest integer.

Domain: -INF <= x <= INF

Range: -INF <= y <= INF, y integer

This function operates on single-precision floating point values, use SDL_floor for double-precision floats.

Parameters

  x | floating point value.

Returns
  the floor of x.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_floor
  SDL_ceilf
  SDL_truncf
  SDL_roundf
  SDL_lroundf

## SDL_fmod()

double SDL_fmod | ( | double | x,
|  | double | y )

extern

Return the floating-point remainder of x / y

Divides x by y, and returns the remainder.

Domain: -INF <= x <= INF, -INF <= y <= INF, y != 0

Range: -y <= z <= y

This function operates on double-precision floating point values, use SDL_fmodf for single-precision floats.

Parameters

  x | the numerator.
  y | the denominator. Must not be 0.

Returns
  the remainder of x / y.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_fmodf
  SDL_modf
  SDL_trunc
  SDL_ceil
  SDL_floor
  SDL_round
  SDL_lround

## SDL_fmodf()

float SDL_fmodf | ( | float | x,
|  | float | y )

extern

Return the floating-point remainder of x / y

Divides x by y, and returns the remainder.

Domain: -INF <= x <= INF, -INF <= y <= INF, y != 0

Range: -y <= z <= y

This function operates on single-precision floating point values, use SDL_fmod for double-precision floats.

Parameters

  x | the numerator.
  y | the denominator. Must not be 0.

Returns
  the remainder of x / y.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_fmod
  SDL_truncf
  SDL_modff
  SDL_ceilf
  SDL_floorf
  SDL_roundf
  SDL_lroundf

## SDL_free()

void SDL_free | ( | void * | mem | ) |

extern

Free allocated memory.

The pointer is no longer valid after this call and cannot be dereferenced anymore.

If mem is NULL, this function does nothing.

Parameters

  mem | a pointer to allocated memory, or NULL.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_malloc
  SDL_calloc
  SDL_realloc

References SDL_free().

Referenced by SDL_free().

## SDL_getenv()

const char * SDL_getenv | ( | const char * | name | ) |

extern

Get the value of a variable in the environment.

The name of the variable is case sensitive on all platforms.

This function uses SDL's cached copy of the environment and is thread-safe.

Parameters

  name | the name of the variable to get.

Returns
  a pointer to the value of the variable or NULL if it can't be found.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

References SDL_getenv().

Referenced by SDL_getenv().

## SDL_getenv_unsafe()

const char * SDL_getenv_unsafe | ( | const char * | name | ) |

extern

Get the value of a variable in the environment.

This function bypasses SDL's cached copy of the environment and is not thread-safe.

On some platforms, this may make case-insensitive matches, while other platforms are case-sensitive. It is best to be precise with strings used for queries through this interface. SDL_getenv is always case-sensitive, however.

Parameters

  name | the name of the variable to get.

Returns
  a pointer to the value of the variable or NULL if it can't be found.

\threadsafety This function is not thread safe, consider using SDL_getenv() instead.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_getenv

References SDL_getenv_unsafe().

Referenced by SDL_getenv_unsafe().

## SDL_GetEnvironment()

SDL_Environment * SDL_GetEnvironment | ( | void |  | ) |

extern

Get the process environment.

This is initialized at application start and is not affected by setenv() and unsetenv() calls after that point. Use SDL_SetEnvironmentVariable() and SDL_UnsetEnvironmentVariable() if you want to modify this environment, or SDL_setenv_unsafe() or SDL_unsetenv_unsafe() if you want changes to persist in the C runtime environment after SDL_Quit().

Returns
  a pointer to the environment for the process or NULL on failure; call SDL_GetError() for more information.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_GetEnvironmentVariable
  SDL_GetEnvironmentVariables
  SDL_SetEnvironmentVariable
  SDL_UnsetEnvironmentVariable

References SDL_GetEnvironment().

Referenced by SDL_GetEnvironment().

## SDL_GetEnvironmentVariable()

const char * SDL_GetEnvironmentVariable | ( | SDL_Environment * | env,
|  | const char * | name )

extern

Get the value of a variable in the environment.

Parameters

  env | the environment to query.
  name | the name of the variable to get.

Returns
  a pointer to the value of the variable or NULL if it can't be found.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_GetEnvironment
  SDL_CreateEnvironment
  SDL_GetEnvironmentVariables
  SDL_SetEnvironmentVariable
  SDL_UnsetEnvironmentVariable

References SDL_GetEnvironmentVariable().

Referenced by SDL_GetEnvironmentVariable().

## SDL_GetEnvironmentVariables()

char ** SDL_GetEnvironmentVariables | ( | SDL_Environment * | env | ) |

extern

Get all variables in the environment.

Parameters

  env | the environment to query.

Returns
  a NULL terminated array of pointers to environment variables in the form "variable=value" or NULL on failure; call SDL_GetError() for more information. This is a single allocation that should be freed with SDL_free() when it is no longer needed.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_GetEnvironment
  SDL_CreateEnvironment
  SDL_GetEnvironmentVariables
  SDL_SetEnvironmentVariable
  SDL_UnsetEnvironmentVariable

References SDL_GetEnvironmentVariables().

Referenced by SDL_GetEnvironmentVariables().

## SDL_GetMemoryFunctions()

void SDL_GetMemoryFunctions | ( | SDL_malloc_func * | malloc_func,
|  | SDL_calloc_func * | calloc_func,
|  | SDL_realloc_func * | realloc_func,
|  | SDL_free_func * | free_func )

extern

Get the current set of SDL memory functions.

Parameters

  malloc_func | filled with malloc function.
  calloc_func | filled with calloc function.
  realloc_func | filled with realloc function.
  free_func | filled with free function.

\threadsafety This does not hold a lock, so do not call this in the unlikely event of a background thread calling SDL_SetMemoryFunctions simultaneously.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_SetMemoryFunctions
  SDL_GetOriginalMemoryFunctions

References SDL_GetMemoryFunctions().

Referenced by SDL_GetMemoryFunctions().

## SDL_GetNumAllocations()

int SDL_GetNumAllocations | ( | void |  | ) |

extern

Get the number of outstanding (unfreed) allocations.

Returns
  the number of allocations or -1 if allocation counting is disabled.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

References SDL_GetNumAllocations().

Referenced by SDL_GetNumAllocations().

## SDL_GetOriginalMemoryFunctions()

void SDL_GetOriginalMemoryFunctions | ( | SDL_malloc_func * | malloc_func,
|  | SDL_calloc_func * | calloc_func,
|  | SDL_realloc_func * | realloc_func,
|  | SDL_free_func * | free_func )

extern

Get the original set of SDL memory functions.

This is what SDL_malloc and friends will use by default, if there has been no call to SDL_SetMemoryFunctions. This is not necessarily using the C runtime's malloc functions behind the scenes! Different platforms and build configurations might do any number of unexpected things.

Parameters

  malloc_func | filled with malloc function.
  calloc_func | filled with calloc function.
  realloc_func | filled with realloc function.
  free_func | filled with free function.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

References SDL_GetOriginalMemoryFunctions().

Referenced by SDL_GetOriginalMemoryFunctions().

## SDL_iconv()

size_t SDL_iconv | ( | SDL_iconv_t | cd,
|  | const char ** | inbuf,
|  | size_t * | inbytesleft,
|  | char ** | outbuf,
|  | size_t * | outbytesleft )

extern

This function converts text between encodings, reading from and writing to a buffer.

It returns the number of successful conversions on success. On error, SDL_ICONV_E2BIG is returned when the output buffer is too small, or SDL_ICONV_EILSEQ is returned when an invalid input sequence is encountered, or SDL_ICONV_EINVAL is returned when an incomplete input sequence is encountered.

On exit:

- inbuf will point to the beginning of the next multibyte sequence. On error, this is the location of the problematic input sequence. On success, this is the end of the input sequence.
- inbytesleft will be set to the number of bytes left to convert, which will be 0 on success.
- outbuf will point to the location where to store the next output byte.
- outbytesleft will be set to the number of bytes left in the output buffer.

Parameters

  cd | The character set conversion context, created in SDL_iconv_open().
  inbuf | Address of variable that points to the first character of the input sequence.
  inbytesleft | The number of bytes in the input buffer.
  outbuf | Address of variable that points to the output buffer.
  outbytesleft | The number of bytes in the output buffer.

Returns
  the number of conversions on success, or a negative error code.

\threadsafety Do not use the same SDL_iconv_t from two threads at once.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_iconv_open
  SDL_iconv_close
  SDL_iconv_string

## SDL_iconv_close()

int SDL_iconv_close | ( | SDL_iconv_t | cd | ) |

extern

This function frees a context used for character set conversion.

Parameters

  cd | The character set conversion handle.

Returns
  0 on success, or -1 on failure.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_iconv
  SDL_iconv_open
  SDL_iconv_string

## SDL_iconv_open()

SDL_iconv_t SDL_iconv_open | ( | const char * | tocode,
|  | const char * | fromcode )

extern

This function allocates a context for the specified character set conversion.

Parameters

  tocode | The target character encoding, must not be NULL.
  fromcode | The source character encoding, must not be NULL.

Returns
  a handle that must be freed with SDL_iconv_close, or SDL_ICONV_ERROR on failure.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_iconv
  SDL_iconv_close
  SDL_iconv_string

## SDL_iconv_string()

char * SDL_iconv_string | ( | const char * | tocode,
|  | const char * | fromcode,
|  | const char * | inbuf,
|  | size_t | inbytesleft )

extern

Helper function to convert a string's encoding in one call.

This function converts a buffer or string between encodings in one pass.

The string does not need to be NULL-terminated; this function operates on the number of bytes specified in inbytesleft whether there is a NULL character anywhere in the buffer.

The returned string is owned by the caller, and should be passed to SDL_free when no longer needed.

Parameters

  tocode | the character encoding of the output string. Examples are "UTF-8", "UCS-4", etc.
  fromcode | the character encoding of data in inbuf.
  inbuf | the string to convert to a different encoding.
  inbytesleft | the size of the input string in bytes.

Returns
  a new string, converted to the new encoding, or NULL on error.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_iconv_open
  SDL_iconv_close
  SDL_iconv

## SDL_isalnum()

int SDL_isalnum | ( | int | x | ) |

extern

Query if a character is alphabetic (a letter) or a number.

WARNING: Regardless of system locale, this will only treat ASCII values for English 'a-z', 'A-Z', and '0-9' as true.

Parameters

  x | character value to check.

Returns
  non-zero if x falls within the character class, zero otherwise.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

## SDL_isalpha()

int SDL_isalpha | ( | int | x | ) |

extern

Query if a character is alphabetic (a letter).

WARNING: Regardless of system locale, this will only treat ASCII values for English 'a-z' and 'A-Z' as true.

Parameters

  x | character value to check.

Returns
  non-zero if x falls within the character class, zero otherwise.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

## SDL_isblank()

int SDL_isblank | ( | int | x | ) |

extern

Report if a character is blank (a space or tab).

WARNING: Regardless of system locale, this will only treat ASCII values 0x20 (space) or 0x9 (tab) as true.

Parameters

  x | character value to check.

Returns
  non-zero if x falls within the character class, zero otherwise.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

## SDL_iscntrl()

int SDL_iscntrl | ( | int | x | ) |

extern

Report if a character is a control character.

WARNING: Regardless of system locale, this will only treat ASCII values 0 through 0x1F, and 0x7F, as true.

Parameters

  x | character value to check.

Returns
  non-zero if x falls within the character class, zero otherwise.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

## SDL_isdigit()

int SDL_isdigit | ( | int | x | ) |

extern

Report if a character is a numeric digit.

WARNING: Regardless of system locale, this will only treat ASCII values '0' (0x30) through '9' (0x39), as true.

Parameters

  x | character value to check.

Returns
  non-zero if x falls within the character class, zero otherwise.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

## SDL_isgraph()

int SDL_isgraph | ( | int | x | ) |

extern

Report if a character is any "printable" except space.

Be advised that "printable" has a definition that goes back to text terminals from the dawn of computing, making this a sort of special case function that is not suitable for Unicode (or most any) text management.

WARNING: Regardless of system locale, this is equivalent to (SDL_isprint(x)) && ((x) != ' ').

Parameters

  x | character value to check.

Returns
  non-zero if x falls within the character class, zero otherwise.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_isprint

## SDL_isinf()

int SDL_isinf | ( | double | x | ) |

extern

Return whether the value is infinity.

Parameters

  x | double-precision floating point value.

Returns
  non-zero if the value is infinity, 0 otherwise.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_isinff

## SDL_isinff()

int SDL_isinff | ( | float | x | ) |

extern

Return whether the value is infinity.

Parameters

  x | floating point value.

Returns
  non-zero if the value is infinity, 0 otherwise.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_isinf

## SDL_islower()

int SDL_islower | ( | int | x | ) |

extern

Report if a character is lower case.

WARNING: Regardless of system locale, this will only treat ASCII values 'a' through 'z' as true.

Parameters

  x | character value to check.

Returns
  non-zero if x falls within the character class, zero otherwise.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

## SDL_isnan()

int SDL_isnan | ( | double | x | ) |

extern

Return whether the value is NaN.

Parameters

  x | double-precision floating point value.

Returns
  non-zero if the value is NaN, 0 otherwise.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_isnanf

## SDL_isnanf()

int SDL_isnanf | ( | float | x | ) |

extern

Return whether the value is NaN.

Parameters

  x | floating point value.

Returns
  non-zero if the value is NaN, 0 otherwise.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_isnan

## SDL_isprint()

int SDL_isprint | ( | int | x | ) |

extern

Report if a character is "printable".

Be advised that "printable" has a definition that goes back to text terminals from the dawn of computing, making this a sort of special case function that is not suitable for Unicode (or most any) text management.

WARNING: Regardless of system locale, this will only treat ASCII values ' ' (0x20) through '~' (0x7E) as true.

Parameters

  x | character value to check.

Returns
  non-zero if x falls within the character class, zero otherwise.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

## SDL_ispunct()

int SDL_ispunct | ( | int | x | ) |

extern

Report if a character is a punctuation mark.

WARNING: Regardless of system locale, this is equivalent to ((SDL_isgraph(x)) && (!SDL_isalnum(x))).

Parameters

  x | character value to check.

Returns
  non-zero if x falls within the character class, zero otherwise.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_isgraph
  SDL_isalnum

## SDL_isspace()

int SDL_isspace | ( | int | x | ) |

extern

Report if a character is whitespace.

WARNING: Regardless of system locale, this will only treat the following ASCII values as true:

- space (0x20)
- tab (0x09)
- newline (0x0A)
- vertical tab (0x0B)
- form feed (0x0C)
- return (0x0D)

Parameters

  x | character value to check.

Returns
  non-zero if x falls within the character class, zero otherwise.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

## SDL_isupper()

int SDL_isupper | ( | int | x | ) |

extern

Report if a character is upper case.

WARNING: Regardless of system locale, this will only treat ASCII values 'A' through 'Z' as true.

Parameters

  x | character value to check.

Returns
  non-zero if x falls within the character class, zero otherwise.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

## SDL_isxdigit()

int SDL_isxdigit | ( | int | x | ) |

extern

Report if a character is a hexadecimal digit.

WARNING: Regardless of system locale, this will only treat ASCII values 'A' through 'F', 'a' through 'f', and '0' through '9', as true.

Parameters

  x | character value to check.

Returns
  non-zero if x falls within the character class, zero otherwise.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

## SDL_itoa()

char * SDL_itoa | ( | int | value,
|  | char * | str,
|  | int | radix )

extern

Convert an integer into a string.

This requires a radix to specified for string format. Specifying 10 produces a decimal number, 16 hexadecimal, etc. Must be in the range of 2 to 36.

Note that this function will overflow a buffer if str is not large enough to hold the output! It may be safer to use SDL_snprintf to clamp output, or SDL_asprintf to allocate a buffer. Otherwise, it doesn't hurt to allocate much more space than you expect to use (and don't forget possible negative signs, null terminator bytes, etc).

Parameters

  value | the integer to convert.
  str | the buffer to write the string into.
  radix | the radix to use for string generation.

Returns
  str.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_uitoa
  SDL_ltoa
  SDL_lltoa

## SDL_lltoa()

char * SDL_lltoa | ( | long long | value,
|  | char * | str,
|  | int | radix )

extern

Convert a long long integer into a string.

This requires a radix to specified for string format. Specifying 10 produces a decimal number, 16 hexadecimal, etc. Must be in the range of 2 to 36.

Note that this function will overflow a buffer if str is not large enough to hold the output! It may be safer to use SDL_snprintf to clamp output, or SDL_asprintf to allocate a buffer. Otherwise, it doesn't hurt to allocate much more space than you expect to use (and don't forget possible negative signs, null terminator bytes, etc).

Parameters

  value | the long long integer to convert.
  str | the buffer to write the string into.
  radix | the radix to use for string generation.

Returns
  str.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_ulltoa
  SDL_itoa
  SDL_ltoa

## SDL_log()

double SDL_log | ( | double | x | ) |

extern

Compute the natural logarithm of x.

Domain: 0 < x <= INF

Range: -INF <= y <= INF

It is an error for x to be less than or equal to 0.

This function operates on double-precision floating point values, use SDL_logf for single-precision floats.

This function may use a different approximation across different versions, platforms and configurations. i.e, it can return a different value given the same input on different machines or operating systems, or if SDL is updated.

Parameters

  x | floating point value. Must be greater than 0.

Returns
  the natural logarithm of x.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_logf
  SDL_log10
  SDL_exp

## SDL_log10()

double SDL_log10 | ( | double | x | ) |

extern

Compute the base-10 logarithm of x.

Domain: 0 < x <= INF

Range: -INF <= y <= INF

It is an error for x to be less than or equal to 0.

This function operates on double-precision floating point values, use SDL_log10f for single-precision floats.

This function may use a different approximation across different versions, platforms and configurations. i.e, it can return a different value given the same input on different machines or operating systems, or if SDL is updated.

Parameters

  x | floating point value. Must be greater than 0.

Returns
  the logarithm of x.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_log10f
  SDL_log
  SDL_pow

## SDL_log10f()

float SDL_log10f | ( | float | x | ) |

extern

Compute the base-10 logarithm of x.

Domain: 0 < x <= INF

Range: -INF <= y <= INF

It is an error for x to be less than or equal to 0.

This function operates on single-precision floating point values, use SDL_log10 for double-precision floats.

This function may use a different approximation across different versions, platforms and configurations. i.e, it can return a different value given the same input on different machines or operating systems, or if SDL is updated.

Parameters

  x | floating point value. Must be greater than 0.

Returns
  the logarithm of x.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_log10
  SDL_logf
  SDL_powf

## SDL_logf()

float SDL_logf | ( | float | x | ) |

extern

Compute the natural logarithm of x.

Domain: 0 < x <= INF

Range: -INF <= y <= INF

It is an error for x to be less than or equal to 0.

This function operates on single-precision floating point values, use SDL_log for double-precision floats.

This function may use a different approximation across different versions, platforms and configurations. i.e, it can return a different value given the same input on different machines or operating systems, or if SDL is updated.

Parameters

  x | floating point value. Must be greater than 0.

Returns
  the natural logarithm of x.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_log
  SDL_expf

## SDL_lround()

long SDL_lround | ( | double | x | ) |

extern

Round x to the nearest integer representable as a long

Rounds x to the nearest integer. Values halfway between integers will be rounded away from zero.

Domain: -INF <= x <= INF

Range: MIN_LONG <= y <= MAX_LONG

This function operates on double-precision floating point values, use SDL_lroundf for single-precision floats. To get the result as a floating-point type, use SDL_round.

Parameters

  x | floating point value.

Returns
  the nearest integer to x.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_lroundf
  SDL_round
  SDL_floor
  SDL_ceil
  SDL_trunc

## SDL_lroundf()

long SDL_lroundf | ( | float | x | ) |

extern

Round x to the nearest integer representable as a long

Rounds x to the nearest integer. Values halfway between integers will be rounded away from zero.

Domain: -INF <= x <= INF

Range: MIN_LONG <= y <= MAX_LONG

This function operates on single-precision floating point values, use SDL_lround for double-precision floats. To get the result as a floating-point type, use SDL_roundf.

Parameters

  x | floating point value.

Returns
  the nearest integer to x.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_lround
  SDL_roundf
  SDL_floorf
  SDL_ceilf
  SDL_truncf

## SDL_ltoa()

char * SDL_ltoa | ( | long | value,
|  | char * | str,
|  | int | radix )

extern

Convert a long integer into a string.

This requires a radix to specified for string format. Specifying 10 produces a decimal number, 16 hexadecimal, etc. Must be in the range of 2 to 36.

Note that this function will overflow a buffer if str is not large enough to hold the output! It may be safer to use SDL_snprintf to clamp output, or SDL_asprintf to allocate a buffer. Otherwise, it doesn't hurt to allocate much more space than you expect to use (and don't forget possible negative signs, null terminator bytes, etc).

Parameters

  value | the long integer to convert.
  str | the buffer to write the string into.
  radix | the radix to use for string generation.

Returns
  str.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_ultoa
  SDL_itoa
  SDL_lltoa

## SDL_malloc()

SDL_MALLOC void * SDL_malloc | ( | size_t | size | ) |

extern

Allocate uninitialized memory.

The allocated memory returned by this function must be freed with SDL_free().

If size is 0, it will be set to 1.

If the allocation is successful, the returned pointer is guaranteed to be aligned to either the fundamental alignment (alignof(max_align_t) in C11 and later) or 2 * sizeof(void *), whichever is smaller. Use SDL_aligned_alloc() if you need to allocate memory aligned to an alignment greater than this guarantee.

Parameters

  size | the size to allocate.

Returns
  a pointer to the allocated memory, or NULL if allocation failed.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_free
  SDL_calloc
  SDL_realloc
  SDL_aligned_alloc

References SDL_MALLOC, and size.

## SDL_memcmp()

int SDL_memcmp | ( | const void * | s1,
|  | const void * | s2,
|  | size_t | len )

extern

Compare two buffers of memory.

Parameters

  s1 | the first buffer to compare. NULL is not permitted!
  s2 | the second buffer to compare. NULL is not permitted!
  len | the number of bytes to compare between the buffers.

Returns
  less than zero if s1 is "less than" s2, greater than zero if s1 is "greater than" s2, and zero if the buffers match exactly for len bytes.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

## SDL_memcpy()

void * SDL_memcpy | ( | SDL_OUT_BYTECAP(len) void * | dst,
|  | SDL_IN_BYTECAP(len) const void * | src,
|  | size_t | len )

extern

Copy non-overlapping memory.

The memory regions must not overlap. If they do, use SDL_memmove() instead.

Parameters

  dst | The destination memory region. Must not be NULL, and must not overlap with src.
  src | The source memory region. Must not be NULL, and must not overlap with dst.
  len | The length in bytes of both dst and src.

Returns
  dst.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_memmove

## SDL_memmove()

void * SDL_memmove | ( | SDL_OUT_BYTECAP(len) void * | dst,
|  | SDL_IN_BYTECAP(len) const void * | src,
|  | size_t | len )

extern

Copy memory ranges that might overlap.

It is okay for the memory regions to overlap. If you are confident that the regions never overlap, using SDL_memcpy() may improve performance.

Parameters

  dst | The destination memory region. Must not be NULL.
  src | The source memory region. Must not be NULL.
  len | The length in bytes of both dst and src.

Returns
  dst.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_memcpy

## SDL_memset()

void * SDL_memset | ( | SDL_OUT_BYTECAP(len) void * | dst,
|  | int | c,
|  | size_t | len )

extern

Initialize all bytes of buffer of memory to a specific value.

This function will set len bytes, pointed to by dst, to the value specified in c.

Despite c being an int instead of a char, this only operates on bytes; c must be a value between 0 and 255, inclusive.

Parameters

  dst | the destination memory region. Must not be NULL.
  c | the byte value to set.
  len | the length, in bytes, to set in dst.

Returns
  dst.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

## SDL_memset4()

void * SDL_memset4 | ( | void * | dst,
|  | Uint32 | val,
|  | size_t | dwords )

extern

Initialize all 32-bit words of buffer of memory to a specific value.

This function will set a buffer of dwords Uint32 values, pointed to by dst, to the value specified in val.

Unlike SDL_memset, this sets 32-bit values, not bytes, so it's not limited to a range of 0-255.

Parameters

  dst | the destination memory region. Must not be NULL.
  val | the Uint32 value to set.
  dwords | the number of Uint32 values to set in dst.

Returns
  dst.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

## SDL_modf()

double SDL_modf | ( | double | x,
|  | double * | y )

extern

Split x into integer and fractional parts

This function operates on double-precision floating point values, use SDL_modff for single-precision floats.

Parameters

  x | floating point value.
  y | output pointer to store the integer part of x.

Returns
  the fractional part of x.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_modff
  SDL_trunc
  SDL_fmod

## SDL_modff()

float SDL_modff | ( | float | x,
|  | float * | y )

extern

Split x into integer and fractional parts

This function operates on single-precision floating point values, use SDL_modf for double-precision floats.

Parameters

  x | floating point value.
  y | output pointer to store the integer part of x.

Returns
  the fractional part of x.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_modf
  SDL_truncf
  SDL_fmodf

## SDL_murmur3_32()

Uint32 SDL_murmur3_32 | ( | const void * | data,
|  | size_t | len,
|  | Uint32 | seed )

extern

Calculate a 32-bit MurmurHash3 value for a block of data.

https://en.wikipedia.org/wiki/MurmurHash

A seed may be specified, which changes the final results consistently, but this does not work like SDL_crc16 and SDL_crc32: you can't feed a previous result from this function back into itself as the next seed value to calculate a hash in chunks; it won't produce the same hash as it would if the same data was provided in a single call.

If you aren't sure what to provide for a seed, zero is fine. Murmur3 is not cryptographically secure, so it shouldn't be used for hashing top-secret data.

Parameters

  data | the data to be hashed.
  len | the size of data, in bytes.
  seed | a value that alters the final hash value.

Returns
  a Murmur3 32-bit hash value.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

## SDL_pow()

double SDL_pow | ( | double | x,
|  | double | y )

extern

Raise x to the power y

Domain: -INF <= x <= INF, -INF <= y <= INF

Range: -INF <= z <= INF

If y is the base of the natural logarithm (e), consider using SDL_exp instead.

This function operates on double-precision floating point values, use SDL_powf for single-precision floats.

This function may use a different approximation across different versions, platforms and configurations. i.e, it can return a different value given the same input on different machines or operating systems, or if SDL is updated.

Parameters

  x | the base.
  y | the exponent.

Returns
  x raised to the power y.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_powf
  SDL_exp
  SDL_log

## SDL_powf()

float SDL_powf | ( | float | x,
|  | float | y )

extern

Raise x to the power y

Domain: -INF <= x <= INF, -INF <= y <= INF

Range: -INF <= z <= INF

If y is the base of the natural logarithm (e), consider using SDL_exp instead.

This function operates on single-precision floating point values, use SDL_pow for double-precision floats.

This function may use a different approximation across different versions, platforms and configurations. i.e, it can return a different value given the same input on different machines or operating systems, or if SDL is updated.

Parameters

  x | the base.
  y | the exponent.

Returns
  x raised to the power y.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_pow
  SDL_expf
  SDL_logf

## SDL_qsort()

void SDL_qsort | ( | void * | base,
|  | size_t | nmemb,
|  | size_t | size,
|  | SDL_CompareCallback | compare )

extern

Sort an array.

For example:

typedef struct {
int key;
const char *string;
} data;
int SDLCALL compare(const void *a, const void *b)
{
const data *A = (const data *)a;
const data *B = (const data *)b;
if (A->n < B->n) {
return -1;
} else if (B->n < A->n) {
return 1;
} else {
return 0;
}
}
data values[] = {
{ 3, "third" }, { 1, "first" }, { 2, "second" }
};
SDL_qsort(values, SDL_arraysize(values), sizeof(values[0]), compare);
SDL_qsort
void SDL_qsort(void *base, size_t nmemb, size_t size, SDL_CompareCallback compare)

Parameters

  base | a pointer to the start of the array.
  nmemb | the number of elements in the array.
  size | the size of the elements in the array.
  compare | a function used to compare elements in the array.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_bsearch
  SDL_qsort_r

References SDL_qsort(), and size.

Referenced by SDL_qsort().

## SDL_qsort_r()

void SDL_qsort_r | ( | void * | base,
|  | size_t | nmemb,
|  | size_t | size,
|  | SDL_CompareCallback_r | compare,
|  | void * | userdata )

extern

Sort an array, passing a userdata pointer to the compare function.

For example:

typedef enum {
sort_increasing,
sort_decreasing,
} sort_method;
typedef struct {
int key;
const char *string;
} data;
int SDLCALL compare(const void *userdata, const void *a, const void *b)
{
sort_method method = (sort_method)(uintptr_t)userdata;
const data *A = (const data *)a;
const data *B = (const data *)b;
if (A->key < B->key) {
return (method == sort_increasing) ? -1 : 1;
} else if (B->key < A->key) {
return (method == sort_increasing) ? 1 : -1;
} else {
return 0;
}
}
data values[] = {
{ 3, "third" }, { 1, "first" }, { 2, "second" }
};
SDL_qsort_r(values, SDL_arraysize(values), sizeof(values[0]), compare, (const void *)(uintptr_t)sort_increasing);
SDL_qsort_r
void SDL_qsort_r(void *base, size_t nmemb, size_t size, SDL_CompareCallback_r compare, void *userdata)

Parameters

  base | a pointer to the start of the array.
  nmemb | the number of elements in the array.
  size | the size of the elements in the array.
  compare | a function used to compare elements in the array.
  userdata | a pointer to pass to the compare function.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_bsearch_r
  SDL_qsort

References SDL_qsort_r(), and size.

Referenced by SDL_qsort_r().

## SDL_rand()

Sint32 SDL_rand | ( | Sint32 | n | ) |

extern

Generate a pseudo-random number less than n for positive n

The method used is faster and of better quality than rand() % n. Odds are roughly 99.9% even for n = 1 million. Evenness is better for smaller n, and much worse as n gets bigger.

Example: to simulate a d6 use SDL_rand(6) + 1 The +1 converts 0..5 to 1..6

If you want to generate a pseudo-random number in the full range of Sint32, you should use: (Sint32)SDL_rand_bits()

If you want reproducible output, be sure to initialize with SDL_srand() first.

There are no guarantees as to the quality of the random sequence produced, and this should not be used for security (cryptography, passwords) or where money is on the line (loot-boxes, casinos). There are many random number libraries available with different characteristics and you should pick one of those to meet any serious needs.

Parameters

  n | the number of possible outcomes. n must be positive.

Returns
  a random value in the range of [0 .. n-1].

\threadsafety All calls should be made from a single thread

Since
  This function is available since SDL 3.2.0.

See also
  SDL_srand
  SDL_randf

References SDL_rand().

Referenced by SDL_rand().

## SDL_rand_bits()

Uint32 SDL_rand_bits | ( | void |  | ) |

extern

Generate 32 pseudo-random bits.

You likely want to use SDL_rand() to get a psuedo-random number instead.

There are no guarantees as to the quality of the random sequence produced, and this should not be used for security (cryptography, passwords) or where money is on the line (loot-boxes, casinos). There are many random number libraries available with different characteristics and you should pick one of those to meet any serious needs.

Returns
  a random value in the range of [0-SDL_MAX_UINT32].

\threadsafety All calls should be made from a single thread

Since
  This function is available since SDL 3.2.0.

See also
  SDL_rand
  SDL_randf
  SDL_srand

References SDL_rand_bits().

Referenced by SDL_rand_bits().

## SDL_rand_bits_r()

Uint32 SDL_rand_bits_r | ( | Uint64 * | state | ) |

extern

Generate 32 pseudo-random bits.

You likely want to use SDL_rand_r() to get a psuedo-random number instead.

There are no guarantees as to the quality of the random sequence produced, and this should not be used for security (cryptography, passwords) or where money is on the line (loot-boxes, casinos). There are many random number libraries available with different characteristics and you should pick one of those to meet any serious needs.

Parameters

  state | a pointer to the current random number state, this may not be NULL.

Returns
  a random value in the range of [0-SDL_MAX_UINT32].

\threadsafety This function is thread-safe, as long as the state pointer isn't shared between threads.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_rand_r
  SDL_randf_r

References SDL_rand_bits_r().

Referenced by SDL_rand_bits_r().

## SDL_rand_r()

Sint32 SDL_rand_r | ( | Uint64 * | state,
|  | Sint32 | n )

extern

Generate a pseudo-random number less than n for positive n

The method used is faster and of better quality than rand() % n. Odds are roughly 99.9% even for n = 1 million. Evenness is better for smaller n, and much worse as n gets bigger.

Example: to simulate a d6 use SDL_rand_r(state, 6) + 1 The +1 converts 0..5 to 1..6

If you want to generate a pseudo-random number in the full range of Sint32, you should use: (Sint32)SDL_rand_bits_r(state)

There are no guarantees as to the quality of the random sequence produced, and this should not be used for security (cryptography, passwords) or where money is on the line (loot-boxes, casinos). There are many random number libraries available with different characteristics and you should pick one of those to meet any serious needs.

Parameters

  state | a pointer to the current random number state, this may not be NULL.
  n | the number of possible outcomes. n must be positive.

Returns
  a random value in the range of [0 .. n-1].

\threadsafety This function is thread-safe, as long as the state pointer isn't shared between threads.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_rand
  SDL_rand_bits_r
  SDL_randf_r

References SDL_rand_r().

Referenced by SDL_rand_r().

## SDL_randf()

float SDL_randf | ( | void |  | ) |

extern

Generate a uniform pseudo-random floating point number less than 1.0

If you want reproducible output, be sure to initialize with SDL_srand() first.

There are no guarantees as to the quality of the random sequence produced, and this should not be used for security (cryptography, passwords) or where money is on the line (loot-boxes, casinos). There are many random number libraries available with different characteristics and you should pick one of those to meet any serious needs.

Returns
  a random value in the range of [0.0, 1.0).

\threadsafety All calls should be made from a single thread

Since
  This function is available since SDL 3.2.0.

See also
  SDL_srand
  SDL_rand

References SDL_randf().

Referenced by SDL_randf().

## SDL_randf_r()

float SDL_randf_r | ( | Uint64 * | state | ) |

extern

Generate a uniform pseudo-random floating point number less than 1.0

If you want reproducible output, be sure to initialize with SDL_srand() first.

There are no guarantees as to the quality of the random sequence produced, and this should not be used for security (cryptography, passwords) or where money is on the line (loot-boxes, casinos). There are many random number libraries available with different characteristics and you should pick one of those to meet any serious needs.

Parameters

  state | a pointer to the current random number state, this may not be NULL.

Returns
  a random value in the range of [0.0, 1.0).

\threadsafety This function is thread-safe, as long as the state pointer isn't shared between threads.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_rand_bits_r
  SDL_rand_r
  SDL_randf

References SDL_randf_r().

Referenced by SDL_randf_r().

## SDL_round()

double SDL_round | ( | double | x | ) |

extern

Round x to the nearest integer.

Rounds x to the nearest integer. Values halfway between integers will be rounded away from zero.

Domain: -INF <= x <= INF

Range: -INF <= y <= INF, y integer

This function operates on double-precision floating point values, use SDL_roundf for single-precision floats. To get the result as an integer type, use SDL_lround.

Parameters

  x | floating point value.

Returns
  the nearest integer to x.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_roundf
  SDL_lround
  SDL_floor
  SDL_ceil
  SDL_trunc

## SDL_roundf()

float SDL_roundf | ( | float | x | ) |

extern

Round x to the nearest integer.

Rounds x to the nearest integer. Values halfway between integers will be rounded away from zero.

Domain: -INF <= x <= INF

Range: -INF <= y <= INF, y integer

This function operates on single-precision floating point values, use SDL_round for double-precision floats. To get the result as an integer type, use SDL_lroundf.

Parameters

  x | floating point value.

Returns
  the nearest integer to x.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_round
  SDL_lroundf
  SDL_floorf
  SDL_ceilf
  SDL_truncf

## SDL_scalbn()

double SDL_scalbn | ( | double | x,
|  | int | n )

extern

Scale x by an integer power of two.

Multiplies x by the nth power of the floating point radix (always 2).

Domain: -INF <= x <= INF, n integer

Range: -INF <= y <= INF

This function operates on double-precision floating point values, use SDL_scalbnf for single-precision floats.

Parameters

  x | floating point value to be scaled.
  n | integer exponent.

Returns
  x * 2^n.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_scalbnf
  SDL_pow

## SDL_scalbnf()

float SDL_scalbnf | ( | float | x,
|  | int | n )

extern

Scale x by an integer power of two.

Multiplies x by the nth power of the floating point radix (always 2).

Domain: -INF <= x <= INF, n integer

Range: -INF <= y <= INF

This function operates on single-precision floating point values, use SDL_scalbn for double-precision floats.

Parameters

  x | floating point value to be scaled.
  n | integer exponent.

Returns
  x * 2^n.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_scalbn
  SDL_powf

## SDL_setenv_unsafe()

int SDL_setenv_unsafe | ( | const char * | name,
|  | const char * | value,
|  | int | overwrite )

extern

Set the value of a variable in the environment.

Parameters

  name | the name of the variable to set.
  value | the value of the variable to set.
  overwrite | 1 to overwrite the variable if it exists, 0 to return success without setting the variable if it already exists.

Returns
  0 on success, -1 on error.

\threadsafety This function is not thread safe, consider using SDL_SetEnvironmentVariable() instead.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_SetEnvironmentVariable

References SDL_setenv_unsafe().

Referenced by SDL_setenv_unsafe().

## SDL_SetEnvironmentVariable()

bool SDL_SetEnvironmentVariable | ( | SDL_Environment * | env,
|  | const char * | name,
|  | const char * | value,
|  | bool | overwrite )

extern

Set the value of a variable in the environment.

Parameters

  env | the environment to modify.
  name | the name of the variable to set.
  value | the value of the variable to set.
  overwrite | true to overwrite the variable if it exists, false to return success without setting the variable if it already exists.

Returns
  true on success or false on failure; call SDL_GetError() for more information.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_GetEnvironment
  SDL_CreateEnvironment
  SDL_GetEnvironmentVariable
  SDL_GetEnvironmentVariables
  SDL_UnsetEnvironmentVariable

References SDL_SetEnvironmentVariable().

Referenced by SDL_SetEnvironmentVariable().

## SDL_SetMemoryFunctions()

bool SDL_SetMemoryFunctions | ( | SDL_malloc_func | malloc_func,
|  | SDL_calloc_func | calloc_func,
|  | SDL_realloc_func | realloc_func,
|  | SDL_free_func | free_func )

extern

Replace SDL's memory allocation functions with a custom set.

It is not safe to call this function once any allocations have been made, as future calls to SDL_free will use the new allocator, even if they came from an SDL_malloc made with the old one!

If used, usually this needs to be the first call made into the SDL library, if not the very first thing done at program startup time.

Parameters

  malloc_func | custom malloc function.
  calloc_func | custom calloc function.
  realloc_func | custom realloc function.
  free_func | custom free function.

Returns
  true on success or false on failure; call SDL_GetError() for more information.

\threadsafety It is safe to call this function from any thread, but one should not replace the memory functions once any allocations are made!

Since
  This function is available since SDL 3.2.0.

See also
  SDL_GetMemoryFunctions
  SDL_GetOriginalMemoryFunctions

References SDL_SetMemoryFunctions().

Referenced by SDL_SetMemoryFunctions().

## SDL_sin()

double SDL_sin | ( | double | x | ) |

extern

Compute the sine of x.

Domain: -INF <= x <= INF

Range: -1 <= y <= 1

This function operates on double-precision floating point values, use SDL_sinf for single-precision floats.

This function may use a different approximation across different versions, platforms and configurations. i.e, it can return a different value given the same input on different machines or operating systems, or if SDL is updated.

Parameters

  x | floating point value, in radians.

Returns
  sine of x.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_sinf
  SDL_asin
  SDL_cos

## SDL_sinf()

float SDL_sinf | ( | float | x | ) |

extern

Compute the sine of x.

Domain: -INF <= x <= INF

Range: -1 <= y <= 1

This function operates on single-precision floating point values, use SDL_sin for double-precision floats.

This function may use a different approximation across different versions, platforms and configurations. i.e, it can return a different value given the same input on different machines or operating systems, or if SDL is updated.

Parameters

  x | floating point value, in radians.

Returns
  sine of x.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_sin
  SDL_asinf
  SDL_cosf

## SDL_size_add_check_overflow()

SDL_FORCE_INLINE bool SDL_size_add_check_overflow | ( | size_t | a,
|  | size_t | b,
|  | size_t * | ret )

Add two integers, checking for overflow.

If a + b would overflow, return false.

Otherwise store a + b via ret and return true.

Parameters

  a | the first addend.
  b | the second addend.
  ret | on non-overflow output, stores the addition result, may not be NULL.

Returns
  false on overflow, true if result is added without overflow.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

Definition at line 6134 of file SDL_stdinc.h.

{
if (b > SDL_SIZE_MAX - a) {
return false;
}
*ret = a + b;
return true;
}
SDL_SIZE_MAX
#define SDL_SIZE_MAX
Definition SDL_stdinc.h:184

References SDL_FORCE_INLINE, and SDL_SIZE_MAX.

## SDL_size_mul_check_overflow()

SDL_FORCE_INLINE bool SDL_size_mul_check_overflow | ( | size_t | a,
|  | size_t | b,
|  | size_t * | ret )

Multiply two integers, checking for overflow.

If a * b would overflow, return false.

Otherwise store a * b via ret and return true.

Parameters

  a | the multiplicand.
  b | the multiplier.
  ret | on non-overflow output, stores the multiplication result, may not be NULL.

Returns
  false on overflow, true if result is multiplied without overflow.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

Definition at line 6095 of file SDL_stdinc.h.

{
if (a != 0 && b > SDL_SIZE_MAX / a) {
return false;
}
*ret = a * b;
return true;
}

References SDL_FORCE_INLINE, and SDL_SIZE_MAX.

## SDL_snprintf()

int SDL_snprintf | ( | SDL_OUT_Z_CAP(maxlen) char * | text,
|  | size_t | maxlen,
|  | SDL_PRINTF_FORMAT_STRING const char * | fmt,
|  |  | ... )

extern

This works exactly like snprintf() but doesn't require access to a C runtime.

Format a string of up to maxlen-1 bytes, converting each '' item with values provided through variable arguments.

While some C runtimes differ on how to deal with too-large strings, this function null-terminates the output, by treating the null-terminator as part of the maxlen count. Note that if maxlen is zero, however, no bytes will be written at all.

This function returns the number of bytes (not characters) that should be written, excluding the null-terminator character. If this returns a number >= maxlen, it means the output string was truncated. A negative return value means an error occurred.

Referencing the output string's pointer with a format item is undefined behavior.

Parameters

  text | the buffer to write the string into. Must not be NULL.
  maxlen | the maximum bytes to write, including the null-terminator.
  fmt | a printf-style format string. Must not be NULL.
  ... | a list of values to be used with the format string.

Returns
  the number of bytes that should be written, not counting the null-terminator char, or a negative value on error.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

References SDL_OUT_Z_CAP, SDL_PRINTF_FORMAT_STRING, SDL_PRINTF_VARARG_FUNC, and SDL_snprintf().

Referenced by SDL_snprintf().

## SDL_sqrt()

double SDL_sqrt | ( | double | x | ) |

extern

Compute the square root of x.

Domain: 0 <= x <= INF

Range: 0 <= y <= INF

This function operates on double-precision floating point values, use SDL_sqrtf for single-precision floats.

This function may use a different approximation across different versions, platforms and configurations. i.e, it can return a different value given the same input on different machines or operating systems, or if SDL is updated.

Parameters

  x | floating point value. Must be greater than or equal to 0.

Returns
  square root of x.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_sqrtf

## SDL_sqrtf()

float SDL_sqrtf | ( | float | x | ) |

extern

Compute the square root of x.

Domain: 0 <= x <= INF

Range: 0 <= y <= INF

This function operates on single-precision floating point values, use SDL_sqrt for double-precision floats.

This function may use a different approximation across different versions, platforms and configurations. i.e, it can return a different value given the same input on different machines or operating systems, or if SDL is updated.

Parameters

  x | floating point value. Must be greater than or equal to 0.

Returns
  square root of x.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_sqrt

## SDL_srand()

void SDL_srand | ( | Uint64 | seed | ) |

extern

Seeds the pseudo-random number generator.

Reusing the seed number will cause SDL_rand() to repeat the same stream of 'random' numbers.

Parameters

  seed | the value to use as a random number seed, or 0 to use SDL_GetPerformanceCounter().

\threadsafety This should be called on the same thread that calls SDL_rand()

Since
  This function is available since SDL 3.2.0.

See also
  SDL_rand
  SDL_rand_bits
  SDL_randf

References SDL_srand().

Referenced by SDL_srand().

## SDL_sscanf()

int SDL_sscanf | ( | const char * | text,
|  | SDL_SCANF_FORMAT_STRING const char * | fmt,
|  |  | ... )

extern

This works exactly like sscanf() but doesn't require access to a C runtime.

Scan a string, matching a format string, converting each '' item and storing it to pointers provided through variable arguments.

Parameters

  text | the string to scan. Must not be NULL.
  fmt | a printf-style format string. Must not be NULL.
  ... | a list of pointers to values to be filled in with scanned items.

Returns
  the number of items that matched the format string.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

References SDL_SCANF_FORMAT_STRING, and SDL_SCANF_VARARG_FUNC.

## SDL_StepBackUTF8()

Uint32 SDL_StepBackUTF8 | ( | const char * | start,
|  | const char ** | pstr )

extern

Decode a UTF-8 string in reverse, one Unicode codepoint at a time.

This will go to the start of the previous Unicode codepoint in the string, move *pstr to that location and return that codepoint.

If *pstr is already at the start of the string), it will not advance *pstr at all.

Generally this function is called in a loop until it returns zero, adjusting its parameter each iteration.

If an invalid UTF-8 sequence is encountered, this function returns SDL_INVALID_UNICODE_CODEPOINT.

Several things can generate invalid UTF-8 sequences, including overlong encodings, the use of UTF-16 surrogate values, and truncated data. Please refer to RFC3629 for details.

Parameters

  start | a pointer to the beginning of the UTF-8 string.
  pstr | a pointer to a UTF-8 string pointer to be read and adjusted.

Returns
  the previous Unicode codepoint in the string.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

## SDL_StepUTF8()

Uint32 SDL_StepUTF8 | ( | const char ** | pstr,
|  | size_t * | pslen )

extern

Decode a UTF-8 string, one Unicode codepoint at a time.

This will return the first Unicode codepoint in the UTF-8 encoded string in *pstr, and then advance *pstr past any consumed bytes before returning.

It will not access more than *pslen bytes from the string. *pslen will be adjusted, as well, subtracting the number of bytes consumed.

pslen is allowed to be NULL, in which case the string must be NULL-terminated, as the function will blindly read until it sees the NULL char.

if *pslen is zero, it assumes the end of string is reached and returns a zero codepoint regardless of the contents of the string buffer.

If the resulting codepoint is zero (a NULL terminator), or *pslen is zero, it will not advance *pstr or *pslen at all.

Generally this function is called in a loop until it returns zero, adjusting its parameters each iteration.

If an invalid UTF-8 sequence is encountered, this function returns SDL_INVALID_UNICODE_CODEPOINT and advances the string/length by one byte (which is to say, a multibyte sequence might produce several SDL_INVALID_UNICODE_CODEPOINT returns before it syncs to the next valid UTF-8 sequence).

Several things can generate invalid UTF-8 sequences, including overlong encodings, the use of UTF-16 surrogate values, and truncated data. Please refer to RFC3629 for details.

Parameters

  pstr | a pointer to a UTF-8 string pointer to be read and adjusted.
  pslen | a pointer to the number of bytes in the string, to be read and adjusted. NULL is allowed.

Returns
  the first Unicode codepoint in the string.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

## SDL_strcasecmp()

int SDL_strcasecmp | ( | const char * | str1,
|  | const char * | str2 )

extern

Compare two null-terminated UTF-8 strings, case-insensitively.

This will work with Unicode strings, using a technique called "case-folding" to handle the vast majority of case-sensitive human languages regardless of system locale. It can deal with expanding values: a German Eszett character can compare against two ASCII 's' chars and be considered a match, for example. A notable exception: it does not handle the Turkish 'i' character; human language is complicated!

Since this handles Unicode, it expects the string to be well-formed UTF-8 and not a null-terminated string of arbitrary bytes. Bytes that are not valid UTF-8 are treated as Unicode character U+FFFD (REPLACEMENT CHARACTER), which is to say two strings of random bits may turn out to match if they convert to the same amount of replacement characters.

Parameters

  str1 | the first string to compare. NULL is not permitted!
  str2 | the second string to compare. NULL is not permitted!

Returns
  less than zero if str1 is "less than" str2, greater than zero if str1 is "greater than" str2, and zero if the strings match exactly.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

## SDL_strcasestr()

char * SDL_strcasestr | ( | const char * | haystack,
|  | const char * | needle )

extern

Search a UTF-8 string for the first instance of a specific substring, case-insensitively.

This will work with Unicode strings, using a technique called "case-folding" to handle the vast majority of case-sensitive human languages regardless of system locale. It can deal with expanding values: a German Eszett character can compare against two ASCII 's' chars and be considered a match, for example. A notable exception: it does not handle the Turkish 'i' character; human language is complicated!

Since this handles Unicode, it expects the strings to be well-formed UTF-8 and not a null-terminated string of arbitrary bytes. Bytes that are not valid UTF-8 are treated as Unicode character U+FFFD (REPLACEMENT CHARACTER), which is to say two strings of random bits may turn out to match if they convert to the same amount of replacement characters.

Parameters

  haystack | the string to search. Must not be NULL.
  needle | the string to search for. Must not be NULL.

Returns
  a pointer to the first instance of needle in the string, or NULL if not found.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

## SDL_strchr()

char * SDL_strchr | ( | const char * | str,
|  | int | c )

extern

Search a string for the first instance of a specific byte.

The search ends once it finds the requested byte value, or a null terminator byte to end the string.

Note that this looks for bytes, not characters, so you cannot match against a Unicode codepoint > 255, regardless of character encoding.

Parameters

  str | the string to search. Must not be NULL.
  c | the byte value to search for.

Returns
  a pointer to the first instance of c in the string, or NULL if not found.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

## SDL_strcmp()

int SDL_strcmp | ( | const char * | str1,
|  | const char * | str2 )

extern

Compare two null-terminated UTF-8 strings.

Due to the nature of UTF-8 encoding, this will work with Unicode strings, since effectively this function just compares bytes until it hits a null-terminating character. Also due to the nature of UTF-8, this can be used with SDL_qsort() to put strings in (roughly) alphabetical order.

Parameters

  str1 | the first string to compare. NULL is not permitted!
  str2 | the second string to compare. NULL is not permitted!

Returns
  less than zero if str1 is "less than" str2, greater than zero if str1 is "greater than" str2, and zero if the strings match exactly.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

## SDL_strdup()

SDL_MALLOC char * SDL_strdup | ( | const char * | str | ) |

extern

Allocate a copy of a string.

This allocates enough space for a null-terminated copy of str, using SDL_malloc, and then makes a copy of the string into this space.

The returned string is owned by the caller, and should be passed to SDL_free when no longer needed.

Parameters

  str | the string to copy.

Returns
  a pointer to the newly-allocated string.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

References SDL_MALLOC.

## SDL_strlcat()

size_t SDL_strlcat | ( | SDL_INOUT_Z_CAP(maxlen) char * | dst,
|  | const char * | src,
|  | size_t | maxlen )

extern

Concatenate strings.

This function appends up to maxlen - SDL_strlen(dst) - 1 characters from src to the end of the string in dst, then appends a null terminator.

src and dst must not overlap.

If maxlen - SDL_strlen(dst) - 1 is less than or equal to 0, then dst is unmodified.

Parameters

  dst | The destination buffer already containing the first null-terminated string. Must not be NULL and must not overlap with src.
  src | The second null-terminated string. Must not be NULL, and must not overlap with dst.
  maxlen | The length (in characters) of the destination buffer.

Returns
  the length (in characters, excluding the null terminator) of the string in dst plus the length of src.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_strlcpy

## SDL_strlcpy()

size_t SDL_strlcpy | ( | SDL_OUT_Z_CAP(maxlen) char * | dst,
|  | const char * | src,
|  | size_t | maxlen )

extern

Copy a string.

This function copies up to maxlen - 1 characters from src to dst, then appends a null terminator.

If maxlen is 0, no characters are copied and no null terminator is written.

If you want to copy an UTF-8 string but need to ensure that multi-byte sequences are not truncated, consider using SDL_utf8strlcpy().

Parameters

  dst | The destination buffer. Must not be NULL, and must not overlap with src.
  src | The null-terminated string to copy. Must not be NULL, and must not overlap with dst.
  maxlen | The length (in characters) of the destination buffer.

Returns
  the length (in characters, excluding the null terminator) of src.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_strlcat
  SDL_utf8strlcpy

## SDL_strlen()

size_t SDL_strlen | ( | const char * | str | ) |

extern

This works exactly like strlen() but doesn't require access to a C runtime.

Counts the bytes in str, excluding the null terminator.

If you need the length of a UTF-8 string, consider using SDL_utf8strlen().

Parameters

  str | The null-terminated string to read. Must not be NULL.

Returns
  the length (in bytes, excluding the null terminator) of src.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_strnlen
  SDL_utf8strlen
  SDL_utf8strnlen

Referenced by SDL_AppIterate().

## SDL_strlwr()

char * SDL_strlwr | ( | char * | str | ) |

extern

Convert a string to lowercase.

WARNING: Regardless of system locale, this will only convert ASCII values 'A' through 'Z' to lowercase.

This function operates on a null-terminated string of bytes–even if it is malformed UTF-8!–and converts ASCII characters 'A' through 'Z' to their lowercase equivalents in-place, returning the original str pointer.

Parameters

  str | the string to convert in-place. Can not be NULL.

Returns
  the str pointer passed into this function.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_strupr

## SDL_strncasecmp()

int SDL_strncasecmp | ( | const char * | str1,
|  | const char * | str2,
|  | size_t | maxlen )

extern

Compare two UTF-8 strings, case-insensitively, up to a number of bytes.

This will work with Unicode strings, using a technique called "case-folding" to handle the vast majority of case-sensitive human languages regardless of system locale. It can deal with expanding values: a German Eszett character can compare against two ASCII 's' chars and be considered a match, for example. A notable exception: it does not handle the Turkish 'i' character; human language is complicated!

Since this handles Unicode, it expects the string to be well-formed UTF-8 and not a null-terminated string of arbitrary bytes. Bytes that are not valid UTF-8 are treated as Unicode character U+FFFD (REPLACEMENT CHARACTER), which is to say two strings of random bits may turn out to match if they convert to the same amount of replacement characters.

Note that while this function is intended to be used with UTF-8, maxlen specifies a byte limit! If the limit lands in the middle of a multi-byte UTF-8 sequence, it may convert a portion of the final character to one or more Unicode character U+FFFD (REPLACEMENT CHARACTER) so as not to overflow a buffer.

maxlen specifies a maximum number of bytes to compare; if the strings match to this number of bytes (or both have matched to a null-terminator character before this number of bytes), they will be considered equal.

Parameters

  str1 | the first string to compare. NULL is not permitted!
  str2 | the second string to compare. NULL is not permitted!
  maxlen | the maximum number of bytes to compare.

Returns
  less than zero if str1 is "less than" str2, greater than zero if str1 is "greater than" str2, and zero if the strings match exactly.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

## SDL_strncmp()

int SDL_strncmp | ( | const char * | str1,
|  | const char * | str2,
|  | size_t | maxlen )

extern

Compare two UTF-8 strings up to a number of bytes.

Due to the nature of UTF-8 encoding, this will work with Unicode strings, since effectively this function just compares bytes until it hits a null-terminating character. Also due to the nature of UTF-8, this can be used with SDL_qsort() to put strings in (roughly) alphabetical order.

Note that while this function is intended to be used with UTF-8, it is doing a bytewise comparison, and maxlen specifies a byte limit! If the limit lands in the middle of a multi-byte UTF-8 sequence, it will only compare a portion of the final character.

maxlen specifies a maximum number of bytes to compare; if the strings match to this number of bytes (or both have matched to a null-terminator character before this number of bytes), they will be considered equal.

Parameters

  str1 | the first string to compare. NULL is not permitted!
  str2 | the second string to compare. NULL is not permitted!
  maxlen | the maximum number of bytes to compare.

Returns
  less than zero if str1 is "less than" str2, greater than zero if str1 is "greater than" str2, and zero if the strings match exactly.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

## SDL_strndup()

SDL_MALLOC char * SDL_strndup | ( | const char * | str,
|  | size_t | maxlen )

extern

Allocate a copy of a string, up to n characters.

This allocates enough space for a null-terminated copy of str, up to maxlen bytes, using SDL_malloc, and then makes a copy of the string into this space.

If the string is longer than maxlen bytes, the returned string will be maxlen bytes long, plus a null-terminator character that isn't included in the count.

The returned string is owned by the caller, and should be passed to SDL_free when no longer needed.

Parameters

  str | the string to copy.
  maxlen | the maximum length of the copied string, not counting the null-terminator character.

Returns
  a pointer to the newly-allocated string.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

References SDL_MALLOC.

## SDL_strnlen()

size_t SDL_strnlen | ( | const char * | str,
|  | size_t | maxlen )

extern

This works exactly like strnlen() but doesn't require access to a C runtime.

Counts up to a maximum of maxlen bytes in str, excluding the null terminator.

If you need the length of a UTF-8 string, consider using SDL_utf8strnlen().

Parameters

  str | The null-terminated string to read. Must not be NULL.
  maxlen | The maximum amount of bytes to count.

Returns
  the length (in bytes, excluding the null terminator) of src but never more than maxlen.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_strlen
  SDL_utf8strlen
  SDL_utf8strnlen

## SDL_strnstr()

char * SDL_strnstr | ( | const char * | haystack,
|  | const char * | needle,
|  | size_t | maxlen )

extern

Search a string, up to n bytes, for the first instance of a specific substring.

The search ends once it finds the requested substring, or a null terminator byte to end the string, or maxlen bytes have been examined. It is possible to use this function on a string without a null terminator.

Note that this looks for strings of bytes, not characters, so it's legal to search for malformed and incomplete UTF-8 sequences.

Parameters

  haystack | the string to search. Must not be NULL.
  needle | the string to search for. Must not be NULL.
  maxlen | the maximum number of bytes to search in haystack.

Returns
  a pointer to the first instance of needle in the string, or NULL if not found.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

## SDL_strpbrk()

char * SDL_strpbrk | ( | const char * | str,
|  | const char * | breakset )

extern

Searches a string for the first occurrence of any character contained in a breakset, and returns a pointer from the string to that character.

Parameters

  str | The null-terminated string to be searched. Must not be NULL, and must not overlap with breakset.
  breakset | A null-terminated string containing the list of characters to look for. Must not be NULL, and must not overlap with str.

Returns
  A pointer to the location, in str, of the first occurrence of a character present in the breakset, or NULL if none is found.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

## SDL_strrchr()

char * SDL_strrchr | ( | const char * | str,
|  | int | c )

extern

Search a string for the last instance of a specific byte.

The search must go until it finds a null terminator byte to end the string.

Note that this looks for bytes, not characters, so you cannot match against a Unicode codepoint > 255, regardless of character encoding.

Parameters

  str | the string to search. Must not be NULL.
  c | the byte value to search for.

Returns
  a pointer to the last instance of c in the string, or NULL if not found.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

## SDL_strrev()

char * SDL_strrev | ( | char * | str | ) |

extern

Reverse a string's contents.

This reverses a null-terminated string in-place. Only the content of the string is reversed; the null-terminator character remains at the end of the reversed string.

WARNING: This function reverses the bytes of the string, not the codepoints. If str is a UTF-8 string with Unicode codepoints > 127, this will ruin the string data. You should only use this function on strings that are completely comprised of low ASCII characters.

Parameters

  str | the string to reverse.

Returns
  str.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

## SDL_strstr()

char * SDL_strstr | ( | const char * | haystack,
|  | const char * | needle )

extern

Search a string for the first instance of a specific substring.

The search ends once it finds the requested substring, or a null terminator byte to end the string.

Note that this looks for strings of bytes, not characters, so it's legal to search for malformed and incomplete UTF-8 sequences.

Parameters

  haystack | the string to search. Must not be NULL.
  needle | the string to search for. Must not be NULL.

Returns
  a pointer to the first instance of needle in the string, or NULL if not found.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

## SDL_strtod()

double SDL_strtod | ( | const char * | str,
|  | char ** | endp )

extern

Parse a double from a string.

This function makes fewer guarantees than the C runtime strtod:

- Only decimal notation is guaranteed to be supported. The handling of scientific and hexadecimal notation is unspecified.
- Whether or not INF and NAN can be parsed is unspecified.
- The precision of the result is unspecified.

Parameters

  str | the null-terminated string to read. Must not be NULL.
  endp | if not NULL, the address of the first invalid character (i.e. the next character after the parsed number) will be written to this pointer.

Returns
  the parsed double, or 0 if no number could be parsed.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_atoi
  SDL_atof
  SDL_strtol
  SDL_strtoll
  SDL_strtoul
  SDL_strtoull

## SDL_strtok_r()

char * SDL_strtok_r | ( | char * | str,
|  | const char * | delim,
|  | char ** | saveptr )

extern

This works exactly like strtok_r() but doesn't require access to a C runtime.

Break a string up into a series of tokens.

To start tokenizing a new string, str should be the non-NULL address of the string to start tokenizing. Future calls to get the next token from the same string should specify a NULL.

Note that this function will overwrite pieces of str with null chars to split it into tokens. This function cannot be used with const/read-only strings!

saveptr just needs to point to a char * that can be overwritten; SDL will use this to save tokenizing state between calls. It is initialized if str is non-NULL, and used to resume tokenizing when str is NULL.

Parameters

  str | the string to tokenize, or NULL to continue tokenizing.
  delim | the delimiter string that separates tokens.
  saveptr | pointer to a char *, used for ongoing state.

Returns
  A pointer to the next token, or NULL if no tokens remain.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

## SDL_strtol()

long SDL_strtol | ( | const char * | str,
|  | char ** | endp,
|  | int | base )

extern

Parse a long from a string.

If str starts with whitespace, then those whitespace characters are skipped before attempting to parse the number.

If the parsed number does not fit inside a long, the result is clamped to the minimum and maximum representable long values.

Parameters

  str | The null-terminated string to read. Must not be NULL.
  endp | If not NULL, the address of the first invalid character (i.e. the next character after the parsed number) will be written to this pointer.
  base | The base of the integer to read. Supported values are 0 and 2 to 36 inclusive. If 0, the base will be inferred from the number's prefix (0x for hexadecimal, 0 for octal, decimal otherwise).

Returns
  the parsed long, or 0 if no number could be parsed.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_atoi
  SDL_atof
  SDL_strtoul
  SDL_strtoll
  SDL_strtoull
  SDL_strtod
  SDL_ltoa
  SDL_wcstol

## SDL_strtoll()

long long SDL_strtoll | ( | const char * | str,
|  | char ** | endp,
|  | int | base )

extern

Parse a long long from a string.

If str starts with whitespace, then those whitespace characters are skipped before attempting to parse the number.

If the parsed number does not fit inside a long long, the result is clamped to the minimum and maximum representable long long values.

Parameters

  str | The null-terminated string to read. Must not be NULL.
  endp | If not NULL, the address of the first invalid character (i.e. the next character after the parsed number) will be written to this pointer.
  base | The base of the integer to read. Supported values are 0 and 2 to 36 inclusive. If 0, the base will be inferred from the number's prefix (0x for hexadecimal, 0 for octal, decimal otherwise).

Returns
  the parsed long long, or 0 if no number could be parsed.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_atoi
  SDL_atof
  SDL_strtol
  SDL_strtoul
  SDL_strtoull
  SDL_strtod
  SDL_lltoa

## SDL_strtoul()

unsigned long SDL_strtoul | ( | const char * | str,
|  | char ** | endp,
|  | int | base )

extern

Parse an unsigned long from a string.

If str starts with whitespace, then those whitespace characters are skipped before attempting to parse the number.

If the parsed number does not fit inside an unsigned long, the result is clamped to the maximum representable unsigned long value.

Parameters

  str | The null-terminated string to read. Must not be NULL.
  endp | If not NULL, the address of the first invalid character (i.e. the next character after the parsed number) will be written to this pointer.
  base | The base of the integer to read. Supported values are 0 and 2 to 36 inclusive. If 0, the base will be inferred from the number's prefix (0x for hexadecimal, 0 for octal, decimal otherwise).

Returns
  the parsed unsigned long, or 0 if no number could be parsed.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_atoi
  SDL_atof
  SDL_strtol
  SDL_strtoll
  SDL_strtoull
  SDL_strtod
  SDL_ultoa

## SDL_strtoull()

unsigned long long SDL_strtoull | ( | const char * | str,
|  | char ** | endp,
|  | int | base )

extern

Parse an unsigned long long from a string.

If str starts with whitespace, then those whitespace characters are skipped before attempting to parse the number.

If the parsed number does not fit inside an unsigned long long, the result is clamped to the maximum representable unsigned long long value.

Parameters

  str | The null-terminated string to read. Must not be NULL.
  endp | If not NULL, the address of the first invalid character (i.e. the next character after the parsed number) will be written to this pointer.
  base | The base of the integer to read. Supported values are 0 and 2 to 36 inclusive. If 0, the base will be inferred from the number's prefix (0x for hexadecimal, 0 for octal, decimal otherwise).

Returns
  the parsed unsigned long long, or 0 if no number could be parsed.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_atoi
  SDL_atof
  SDL_strtol
  SDL_strtoll
  SDL_strtoul
  SDL_strtod
  SDL_ulltoa

## SDL_strupr()

char * SDL_strupr | ( | char * | str | ) |

extern

Convert a string to uppercase.

WARNING: Regardless of system locale, this will only convert ASCII values 'A' through 'Z' to uppercase.

This function operates on a null-terminated string of bytes–even if it is malformed UTF-8!–and converts ASCII characters 'a' through 'z' to their uppercase equivalents in-place, returning the original str pointer.

Parameters

  str | the string to convert in-place. Can not be NULL.

Returns
  the str pointer passed into this function.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_strlwr

## SDL_swprintf()

int SDL_swprintf | ( | SDL_OUT_Z_CAP(maxlen) wchar_t * | text,
|  | size_t | maxlen,
|  | SDL_PRINTF_FORMAT_STRING const wchar_t * | fmt,
|  |  | ... )

extern

This works exactly like swprintf() but doesn't require access to a C runtime.

Format a wide string of up to maxlen-1 wchar_t values, converting each '' item with values provided through variable arguments.

While some C runtimes differ on how to deal with too-large strings, this function null-terminates the output, by treating the null-terminator as part of the maxlen count. Note that if maxlen is zero, however, no wide characters will be written at all.

This function returns the number of wide characters (not codepoints) that should be written, excluding the null-terminator character. If this returns a number >= maxlen, it means the output string was truncated. A negative return value means an error occurred.

Referencing the output string's pointer with a format item is undefined behavior.

Parameters

  text | the buffer to write the wide string into. Must not be NULL.
  maxlen | the maximum wchar_t values to write, including the null-terminator.
  fmt | a printf-style format string. Must not be NULL.
  ... | a list of values to be used with the format string.

Returns
  the number of wide characters that should be written, not counting the null-terminator char, or a negative value on error.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

References SDL_OUT_Z_CAP, SDL_PRINTF_FORMAT_STRING, SDL_swprintf(), and SDL_WPRINTF_VARARG_FUNC.

Referenced by SDL_swprintf().

## SDL_tan()

double SDL_tan | ( | double | x | ) |

extern

Compute the tangent of x.

Domain: -INF <= x <= INF

Range: -INF <= y <= INF

This function operates on double-precision floating point values, use SDL_tanf for single-precision floats.

This function may use a different approximation across different versions, platforms and configurations. i.e, it can return a different value given the same input on different machines or operating systems, or if SDL is updated.

Parameters

  x | floating point value, in radians.

Returns
  tangent of x.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_tanf
  SDL_sin
  SDL_cos
  SDL_atan
  SDL_atan2

## SDL_tanf()

float SDL_tanf | ( | float | x | ) |

extern

Compute the tangent of x.

Domain: -INF <= x <= INF

Range: -INF <= y <= INF

This function operates on single-precision floating point values, use SDL_tan for double-precision floats.

This function may use a different approximation across different versions, platforms and configurations. i.e, it can return a different value given the same input on different machines or operating systems, or if SDL is updated.

Parameters

  x | floating point value, in radians.

Returns
  tangent of x.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_tan
  SDL_sinf
  SDL_cosf
  SDL_atanf
  SDL_atan2f

## SDL_tolower()

int SDL_tolower | ( | int | x | ) |

extern

Convert low-ASCII English letters to lowercase.

WARNING: Regardless of system locale, this will only convert ASCII values 'A' through 'Z' to lowercase.

This function returns the lowercase equivalent of x. If a character cannot be converted, or is already lowercase, this function returns x.

Parameters

  x | character value to check.

Returns
  lowercase version of x, or x if no conversion available.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

## SDL_toupper()

int SDL_toupper | ( | int | x | ) |

extern

Convert low-ASCII English letters to uppercase.

WARNING: Regardless of system locale, this will only convert ASCII values 'a' through 'z' to uppercase.

This function returns the uppercase equivalent of x. If a character cannot be converted, or is already uppercase, this function returns x.

Parameters

  x | character value to check.

Returns
  capitalized version of x, or x if no conversion available.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

## SDL_trunc()

double SDL_trunc | ( | double | x | ) |

extern

Truncate x to an integer.

Rounds x to the next closest integer to 0. This is equivalent to removing the fractional part of x, leaving only the integer part.

Domain: -INF <= x <= INF

Range: -INF <= y <= INF, y integer

This function operates on double-precision floating point values, use SDL_truncf for single-precision floats.

Parameters

  x | floating point value.

Returns
  x truncated to an integer.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_truncf
  SDL_fmod
  SDL_ceil
  SDL_floor
  SDL_round
  SDL_lround

## SDL_truncf()

float SDL_truncf | ( | float | x | ) |

extern

Truncate x to an integer.

Rounds x to the next closest integer to 0. This is equivalent to removing the fractional part of x, leaving only the integer part.

Domain: -INF <= x <= INF

Range: -INF <= y <= INF, y integer

This function operates on single-precision floating point values, use SDL_trunc for double-precision floats.

Parameters

  x | floating point value.

Returns
  x truncated to an integer.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_trunc
  SDL_fmodf
  SDL_ceilf
  SDL_floorf
  SDL_roundf
  SDL_lroundf

## SDL_UCS4ToUTF8()

char * SDL_UCS4ToUTF8 | ( | Uint32 | codepoint,
|  | char * | dst )

extern

Convert a single Unicode codepoint to UTF-8.

The buffer pointed to by dst must be at least 4 bytes long, as this function may generate between 1 and 4 bytes of output.

This function returns the first byte after the newly-written UTF-8 sequence, which is useful for encoding multiple codepoints in a loop, or knowing where to write a NULL-terminator character to end the string (in either case, plan to have a buffer of more than 4 bytes!).

If codepoint is an invalid value (outside the Unicode range, or a UTF-16 surrogate value, etc), this will use U+FFFD (REPLACEMENT CHARACTER) for the codepoint instead, and not set an error.

If dst is NULL, this returns NULL immediately without writing to the pointer and without setting an error.

Parameters

  codepoint | a Unicode codepoint to convert to UTF-8.
  dst | the location to write the encoded UTF-8. Must point to at least 4 bytes!

Returns
  the first byte past the newly-written UTF-8 sequence.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

## SDL_uitoa()

char * SDL_uitoa | ( | unsigned int | value,
|  | char * | str,
|  | int | radix )

extern

Convert an unsigned integer into a string.

This requires a radix to specified for string format. Specifying 10 produces a decimal number, 16 hexadecimal, etc. Must be in the range of 2 to 36.

Note that this function will overflow a buffer if str is not large enough to hold the output! It may be safer to use SDL_snprintf to clamp output, or SDL_asprintf to allocate a buffer. Otherwise, it doesn't hurt to allocate much more space than you expect to use (and don't forget null terminator bytes, etc).

Parameters

  value | the unsigned integer to convert.
  str | the buffer to write the string into.
  radix | the radix to use for string generation.

Returns
  str.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_itoa
  SDL_ultoa
  SDL_ulltoa

## SDL_ulltoa()

char * SDL_ulltoa | ( | unsigned long long | value,
|  | char * | str,
|  | int | radix )

extern

Convert an unsigned long long integer into a string.

This requires a radix to specified for string format. Specifying 10 produces a decimal number, 16 hexadecimal, etc. Must be in the range of 2 to 36.

Note that this function will overflow a buffer if str is not large enough to hold the output! It may be safer to use SDL_snprintf to clamp output, or SDL_asprintf to allocate a buffer. Otherwise, it doesn't hurt to allocate much more space than you expect to use (and don't forget null terminator bytes, etc).

Parameters

  value | the unsigned long long integer to convert.
  str | the buffer to write the string into.
  radix | the radix to use for string generation.

Returns
  str.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_lltoa
  SDL_uitoa
  SDL_ultoa

## SDL_ultoa()

char * SDL_ultoa | ( | unsigned long | value,
|  | char * | str,
|  | int | radix )

extern

Convert an unsigned long integer into a string.

This requires a radix to specified for string format. Specifying 10 produces a decimal number, 16 hexadecimal, etc. Must be in the range of 2 to 36.

Note that this function will overflow a buffer if str is not large enough to hold the output! It may be safer to use SDL_snprintf to clamp output, or SDL_asprintf to allocate a buffer. Otherwise, it doesn't hurt to allocate much more space than you expect to use (and don't forget null terminator bytes, etc).

Parameters

  value | the unsigned long integer to convert.
  str | the buffer to write the string into.
  radix | the radix to use for string generation.

Returns
  str.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_ltoa
  SDL_uitoa
  SDL_ulltoa

## SDL_unsetenv_unsafe()

int SDL_unsetenv_unsafe | ( | const char * | name | ) |

extern

Clear a variable from the environment.

Parameters

  name | the name of the variable to unset.

Returns
  0 on success, -1 on error.

\threadsafety This function is not thread safe, consider using SDL_UnsetEnvironmentVariable() instead.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_UnsetEnvironmentVariable

References SDL_unsetenv_unsafe().

Referenced by SDL_unsetenv_unsafe().

## SDL_UnsetEnvironmentVariable()

bool SDL_UnsetEnvironmentVariable | ( | SDL_Environment * | env,
|  | const char * | name )

extern

Clear a variable from the environment.

Parameters

  env | the environment to modify.
  name | the name of the variable to unset.

Returns
  true on success or false on failure; call SDL_GetError() for more information.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_GetEnvironment
  SDL_CreateEnvironment
  SDL_GetEnvironmentVariable
  SDL_GetEnvironmentVariables
  SDL_SetEnvironmentVariable
  SDL_UnsetEnvironmentVariable

References SDL_UnsetEnvironmentVariable().

Referenced by SDL_UnsetEnvironmentVariable().

## SDL_utf8strlcpy()

size_t SDL_utf8strlcpy | ( | SDL_OUT_Z_CAP(dst_bytes) char * | dst,
|  | const char * | src,
|  | size_t | dst_bytes )

extern

Copy an UTF-8 string.

This function copies up to dst_bytes - 1 bytes from src to dst while also ensuring that the string written to dst does not end in a truncated multi-byte sequence. Finally, it appends a null terminator.

src and dst must not overlap.

Note that unlike SDL_strlcpy(), this function returns the number of bytes written, not the length of src.

Parameters

  dst | The destination buffer. Must not be NULL, and must not overlap with src.
  src | The null-terminated UTF-8 string to copy. Must not be NULL, and must not overlap with dst.
  dst_bytes | The length (in bytes) of the destination buffer. Must not be 0.

Returns
  the number of bytes written, excluding the null terminator.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_strlcpy

## SDL_utf8strlen()

size_t SDL_utf8strlen | ( | const char * | str | ) |

extern

Count the number of codepoints in a UTF-8 string.

Counts the codepoints, not bytes, in str, excluding the null terminator.

If you need to count the bytes in a string instead, consider using SDL_strlen().

Since this handles Unicode, it expects the strings to be well-formed UTF-8 and not a null-terminated string of arbitrary bytes. Bytes that are not valid UTF-8 are treated as Unicode character U+FFFD (REPLACEMENT CHARACTER), so a malformed or incomplete UTF-8 sequence might increase the count by several replacement characters.

Parameters

  str | The null-terminated UTF-8 string to read. Must not be NULL.

Returns
  The length (in codepoints, excluding the null terminator) of src.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_utf8strnlen
  SDL_strlen

## SDL_utf8strnlen()

size_t SDL_utf8strnlen | ( | const char * | str,
|  | size_t | bytes )

extern

Count the number of codepoints in a UTF-8 string, up to n bytes.

Counts the codepoints, not bytes, in str, excluding the null terminator.

If you need to count the bytes in a string instead, consider using SDL_strnlen().

The counting stops at bytes bytes (not codepoints!). This seems counterintuitive, but makes it easy to express the total size of the string's buffer.

Since this handles Unicode, it expects the strings to be well-formed UTF-8 and not a null-terminated string of arbitrary bytes. Bytes that are not valid UTF-8 are treated as Unicode character U+FFFD (REPLACEMENT CHARACTER), so a malformed or incomplete UTF-8 sequence might increase the count by several replacement characters.

Parameters

  str | The null-terminated UTF-8 string to read. Must not be NULL.
  bytes | The maximum amount of bytes to count.

Returns
  The length (in codepoints, excluding the null terminator) of src but never more than maxlen.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_utf8strlen
  SDL_strnlen

## SDL_vasprintf()

int SDL_vasprintf | ( | char ** | strp,
|  | SDL_PRINTF_FORMAT_STRING const char * | fmt,
|  | va_list | ap )

extern

This works exactly like vasprintf() but doesn't require access to a C runtime.

Functions identically to SDL_asprintf(), except it takes a va_list instead of using ... variable arguments.

Parameters

  strp | on output, is set to the new string. Must not be NULL.
  fmt | a printf-style format string. Must not be NULL.
  ap | a va_list values to be used with the format string.

Returns
  the number of bytes in the newly-allocated string, not counting the null-terminator char, or a negative value on error.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

References SDL_PRINTF_FORMAT_STRING, SDL_PRINTF_VARARG_FUNCV, and SDL_vasprintf().

Referenced by SDL_vasprintf().

## SDL_vsnprintf()

int SDL_vsnprintf | ( | SDL_OUT_Z_CAP(maxlen) char * | text,
|  | size_t | maxlen,
|  | SDL_PRINTF_FORMAT_STRING const char * | fmt,
|  | va_list | ap )

extern

This works exactly like vsnprintf() but doesn't require access to a C runtime.

Functions identically to SDL_snprintf(), except it takes a va_list instead of using ... variable arguments.

Parameters

  text | the buffer to write the string into. Must not be NULL.
  maxlen | the maximum bytes to write, including the null-terminator.
  fmt | a printf-style format string. Must not be NULL.
  ap | a va_list values to be used with the format string.

Returns
  the number of bytes that should be written, not counting the null-terminator char, or a negative value on error.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

References SDL_OUT_Z_CAP, SDL_PRINTF_FORMAT_STRING, SDL_PRINTF_VARARG_FUNCV, and SDL_vsnprintf().

Referenced by SDL_vsnprintf().

## SDL_vsscanf()

int SDL_vsscanf | ( | const char * | text,
|  | SDL_SCANF_FORMAT_STRING const char * | fmt,
|  | va_list | ap )

extern

This works exactly like vsscanf() but doesn't require access to a C runtime.

Functions identically to SDL_sscanf(), except it takes a va_list instead of using ... variable arguments.

Parameters

  text | the string to scan. Must not be NULL.
  fmt | a printf-style format string. Must not be NULL.
  ap | a va_list of pointers to values to be filled in with scanned items.

Returns
  the number of items that matched the format string.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

References SDL_SCANF_FORMAT_STRING, SDL_SCANF_VARARG_FUNCV, and SDL_vsscanf().

Referenced by SDL_vsscanf().

## SDL_vswprintf()

int SDL_vswprintf | ( | SDL_OUT_Z_CAP(maxlen) wchar_t * | text,
|  | size_t | maxlen,
|  | SDL_PRINTF_FORMAT_STRING const wchar_t * | fmt,
|  | va_list | ap )

extern

This works exactly like vswprintf() but doesn't require access to a C runtime.

Functions identically to SDL_swprintf(), except it takes a va_list instead of using ... variable arguments.

Parameters

  text | the buffer to write the string into. Must not be NULL.
  maxlen | the maximum wide characters to write, including the null-terminator.
  fmt | a printf-style format wide string. Must not be NULL.
  ap | a va_list values to be used with the format string.

Returns
  the number of wide characters that should be written, not counting the null-terminator char, or a negative value on error.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

References SDL_OUT_Z_CAP, SDL_PRINTF_FORMAT_STRING, SDL_vswprintf(), and SDL_WPRINTF_VARARG_FUNCV.

Referenced by SDL_vswprintf().

## SDL_wcscasecmp()

int SDL_wcscasecmp | ( | const wchar_t * | str1,
|  | const wchar_t * | str2 )

extern

Compare two null-terminated wide strings, case-insensitively.

This will work with Unicode strings, using a technique called "case-folding" to handle the vast majority of case-sensitive human languages regardless of system locale. It can deal with expanding values: a German Eszett character can compare against two ASCII 's' chars and be considered a match, for example. A notable exception: it does not handle the Turkish 'i' character; human language is complicated!

Depending on your platform, "wchar_t" might be 2 bytes, and expected to be UTF-16 encoded (like Windows), or 4 bytes in UTF-32 format. Since this handles Unicode, it expects the string to be well-formed and not a null-terminated string of arbitrary bytes. Characters that are not valid UTF-16 (or UTF-32) are treated as Unicode character U+FFFD (REPLACEMENT CHARACTER), which is to say two strings of random bits may turn out to match if they convert to the same amount of replacement characters.

Parameters

  str1 | the first string to compare. NULL is not permitted!
  str2 | the second string to compare. NULL is not permitted!

Returns
  less than zero if str1 is "less than" str2, greater than zero if str1 is "greater than" str2, and zero if the strings match exactly.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

## SDL_wcscmp()

int SDL_wcscmp | ( | const wchar_t * | str1,
|  | const wchar_t * | str2 )

extern

Compare two null-terminated wide strings.

This only compares wchar_t values until it hits a null-terminating character; it does not care if the string is well-formed UTF-16 (or UTF-32, depending on your platform's wchar_t size), or uses valid Unicode values.

Parameters

  str1 | the first string to compare. NULL is not permitted!
  str2 | the second string to compare. NULL is not permitted!

Returns
  less than zero if str1 is "less than" str2, greater than zero if str1 is "greater than" str2, and zero if the strings match exactly.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

## SDL_wcsdup()

wchar_t * SDL_wcsdup | ( | const wchar_t * | wstr | ) |

extern

Allocate a copy of a wide string.

This allocates enough space for a null-terminated copy of wstr, using SDL_malloc, and then makes a copy of the string into this space.

The returned string is owned by the caller, and should be passed to SDL_free when no longer needed.

Parameters

  wstr | the string to copy.

Returns
  a pointer to the newly-allocated wide string.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

## SDL_wcslcat()

size_t SDL_wcslcat | ( | SDL_INOUT_Z_CAP(maxlen) wchar_t * | dst,
|  | const wchar_t * | src,
|  | size_t | maxlen )

extern

Concatenate wide strings.

This function appends up to maxlen - SDL_wcslen(dst) - 1 wide characters from src to the end of the wide string in dst, then appends a null terminator.

src and dst must not overlap.

If maxlen - SDL_wcslen(dst) - 1 is less than or equal to 0, then dst is unmodified.

Parameters

  dst | The destination buffer already containing the first null-terminated wide string. Must not be NULL and must not overlap with src.
  src | The second null-terminated wide string. Must not be NULL, and must not overlap with dst.
  maxlen | The length (in wide characters) of the destination buffer.

Returns
  the length (in wide characters, excluding the null terminator) of the string in dst plus the length of src.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_wcslcpy

## SDL_wcslcpy()

size_t SDL_wcslcpy | ( | SDL_OUT_Z_CAP(maxlen) wchar_t * | dst,
|  | const wchar_t * | src,
|  | size_t | maxlen )

extern

Copy a wide string.

This function copies maxlen - 1 wide characters from src to dst, then appends a null terminator.

src and dst must not overlap.

If maxlen is 0, no wide characters are copied and no null terminator is written.

Parameters

  dst | The destination buffer. Must not be NULL, and must not overlap with src.
  src | The null-terminated wide string to copy. Must not be NULL, and must not overlap with dst.
  maxlen | The length (in wide characters) of the destination buffer.

Returns
  the length (in wide characters, excluding the null terminator) of src.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_wcslcat

## SDL_wcslen()

size_t SDL_wcslen | ( | const wchar_t * | wstr | ) |

extern

This works exactly like wcslen() but doesn't require access to a C runtime.

Counts the number of wchar_t values in wstr, excluding the null terminator.

Like SDL_strlen only counts bytes and not codepoints in a UTF-8 string, this counts wchar_t values in a string, even if the string's encoding is of variable width, like UTF-16.

Also be aware that wchar_t is different sizes on different platforms (4 bytes on Linux, 2 on Windows, etc).

Parameters

  wstr | The null-terminated wide string to read. Must not be NULL.

Returns
  the length (in wchar_t values, excluding the null terminator) of wstr.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_wcsnlen
  SDL_utf8strlen
  SDL_utf8strnlen

## SDL_wcsncasecmp()

int SDL_wcsncasecmp | ( | const wchar_t * | str1,
|  | const wchar_t * | str2,
|  | size_t | maxlen )

extern

Compare two wide strings, case-insensitively, up to a number of wchar_t.

This will work with Unicode strings, using a technique called "case-folding" to handle the vast majority of case-sensitive human languages regardless of system locale. It can deal with expanding values: a German Eszett character can compare against two ASCII 's' chars and be considered a match, for example. A notable exception: it does not handle the Turkish 'i' character; human language is complicated!

Depending on your platform, "wchar_t" might be 2 bytes, and expected to be UTF-16 encoded (like Windows), or 4 bytes in UTF-32 format. Since this handles Unicode, it expects the string to be well-formed and not a null-terminated string of arbitrary bytes. Characters that are not valid UTF-16 (or UTF-32) are treated as Unicode character U+FFFD (REPLACEMENT CHARACTER), which is to say two strings of random bits may turn out to match if they convert to the same amount of replacement characters.

Note that while this function might deal with variable-sized characters, maxlen specifies a wchar limit! If the limit lands in the middle of a multi-byte UTF-16 sequence, it may convert a portion of the final character to one or more Unicode character U+FFFD (REPLACEMENT CHARACTER) so as not to overflow a buffer.

maxlen specifies a maximum number of wchar_t values to compare; if the strings match to this number of wchar_t (or both have matched to a null-terminator character before this number of bytes), they will be considered equal.

Parameters

  str1 | the first string to compare. NULL is not permitted!
  str2 | the second string to compare. NULL is not permitted!
  maxlen | the maximum number of wchar_t values to compare.

Returns
  less than zero if str1 is "less than" str2, greater than zero if str1 is "greater than" str2, and zero if the strings match exactly.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

## SDL_wcsncmp()

int SDL_wcsncmp | ( | const wchar_t * | str1,
|  | const wchar_t * | str2,
|  | size_t | maxlen )

extern

Compare two wide strings up to a number of wchar_t values.

This only compares wchar_t values; it does not care if the string is well-formed UTF-16 (or UTF-32, depending on your platform's wchar_t size), or uses valid Unicode values.

Note that while this function is intended to be used with UTF-16 (or UTF-32, depending on your platform's definition of wchar_t), it is comparing raw wchar_t values and not Unicode codepoints: maxlen specifies a wchar_t limit! If the limit lands in the middle of a multi-wchar UTF-16 sequence, it will only compare a portion of the final character.

maxlen specifies a maximum number of wchar_t to compare; if the strings match to this number of wide chars (or both have matched to a null-terminator character before this count), they will be considered equal.

Parameters

  str1 | the first string to compare. NULL is not permitted!
  str2 | the second string to compare. NULL is not permitted!
  maxlen | the maximum number of wchar_t to compare.

Returns
  less than zero if str1 is "less than" str2, greater than zero if str1 is "greater than" str2, and zero if the strings match exactly.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

## SDL_wcsnlen()

size_t SDL_wcsnlen | ( | const wchar_t * | wstr,
|  | size_t | maxlen )

extern

This works exactly like wcsnlen() but doesn't require access to a C runtime.

Counts up to a maximum of maxlen wchar_t values in wstr, excluding the null terminator.

Like SDL_strnlen only counts bytes and not codepoints in a UTF-8 string, this counts wchar_t values in a string, even if the string's encoding is of variable width, like UTF-16.

Also be aware that wchar_t is different sizes on different platforms (4 bytes on Linux, 2 on Windows, etc).

Also, maxlen is a count of wide characters, not bytes!

Parameters

  wstr | The null-terminated wide string to read. Must not be NULL.
  maxlen | The maximum amount of wide characters to count.

Returns
  the length (in wide characters, excluding the null terminator) of wstr but never more than maxlen.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_wcslen
  SDL_utf8strlen
  SDL_utf8strnlen

## SDL_wcsnstr()

wchar_t * SDL_wcsnstr | ( | const wchar_t * | haystack,
|  | const wchar_t * | needle,
|  | size_t | maxlen )

extern

Search a wide string, up to n wide chars, for the first instance of a specific substring.

The search ends once it finds the requested substring, or a null terminator value to end the string, or maxlen wide character have been examined. It is possible to use this function on a wide string without a null terminator.

Note that this looks for strings of wide characters, not codepoints, so it's legal to search for malformed and incomplete UTF-16 sequences.

Parameters

  haystack | the wide string to search. Must not be NULL.
  needle | the wide string to search for. Must not be NULL.
  maxlen | the maximum number of wide characters to search in haystack.

Returns
  a pointer to the first instance of needle in the string, or NULL if not found.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

## SDL_wcsstr()

wchar_t * SDL_wcsstr | ( | const wchar_t * | haystack,
|  | const wchar_t * | needle )

extern

Search a wide string for the first instance of a specific substring.

The search ends once it finds the requested substring, or a null terminator byte to end the string.

Note that this looks for strings of wide characters, not codepoints, so it's legal to search for malformed and incomplete UTF-16 sequences.

Parameters

  haystack | the wide string to search. Must not be NULL.
  needle | the wide string to search for. Must not be NULL.

Returns
  a pointer to the first instance of needle in the string, or NULL if not found.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

## SDL_wcstol()

long SDL_wcstol | ( | const wchar_t * | str,
|  | wchar_t ** | endp,
|  | int | base )

extern

Parse a long from a wide string.

If str starts with whitespace, then those whitespace characters are skipped before attempting to parse the number.

If the parsed number does not fit inside a long, the result is clamped to the minimum and maximum representable long values.

Parameters

  str | The null-terminated wide string to read. Must not be NULL.
  endp | If not NULL, the address of the first invalid wide character (i.e. the next character after the parsed number) will be written to this pointer.
  base | The base of the integer to read. Supported values are 0 and 2 to 36 inclusive. If 0, the base will be inferred from the number's prefix (0x for hexadecimal, 0 for octal, decimal otherwise).

Returns
  the parsed long, or 0 if no number could be parsed.

\threadsafety It is safe to call this function from any thread.

Since
  This function is available since SDL 3.2.0.

See also
  SDL_strtol

## Variable Documentation

## size

size_t size

Definition at line 1367 of file SDL_stdinc.h.

Referenced by SDL_aligned_alloc(), SDL_ALLOC_SIZE(), SDL_ALLOC_SIZE2(), SDL_bsearch(), SDL_bsearch_r(), SDL_CopyGPUBufferToBuffer(), SDL_GetClipboardData(), SDL_GetWindowICCProfile(), SDL_IOFromConstMem(), SDL_IOFromMem(), SDL_malloc(), SDL_qsort(), SDL_qsort_r(), SDL_ReadAsyncIO(), SDL_ReadIO(), SDL_SendGamepadEffect(), SDL_SendJoystickEffect(), SDL_WriteAsyncIO(), SDL_WriteIO(), SDLTest_LogEscapedString(), and SDLTest_RandomAsciiStringOfSize().