SDL_wcstol(3)

πŸ’– SDL_wcstol πŸ’–

okay bestie, welcome to SDL3 FUNCTIONS β€” today's main character is SDL_wcstol, and she's here to pull a whole long out of a wide string. yes, a wide string. wchar_t girlies, this one's for you 🫢


✨ NAME ✨

SDL_wcstol β€” parse a long from a wide string. that's it, that's the whole job, and she does it flawlessly πŸ’…


🌸 SYNOPSIS 🌸

#include <SDL3/SDL_stdinc.h>

long SDL_wcstol(const wchar_t *str, wchar_t **endp, int base);

πŸ¦‹ DESCRIPTION πŸ¦‹

so here's the vibe. if str starts with whitespace, those whitespace characters get skipped before she even attempts to parse the number. like, she's not gonna be bothered by your leading spaces, she's chill like that ✨

and if the parsed number does not fit inside a long? no problem, no crash, no drama β€” the result gets clamped to the minimum and maximum representable long values. she keeps it in range, periodt πŸ‘‘


πŸŽ€ FUNCTION PARAMETERS πŸŽ€

  • str β€” the null-terminated wide string to read. Must not be NULL. fr fr, do not pass NULL here, that's not the move 😭
  • endp β€” if it's not NULL, the address of the first invalid wide character gets written to this pointer. i.e. the very next character after the parsed number β€” that little marker of where she stopped reading. iconic behavior honestly πŸ“
  • base β€” the base of the integer to read. supported values are 0 and 2 to 36 inclusive. and if you pass 0, the base gets inferred from the number's prefix: 0x means hexadecimal, 0 means octal, and decimal otherwise. she reads the room πŸ’œ

πŸ‘‘ RETURN VALUE πŸ‘‘

returns the parsed long, or 0 if no number could be parsed. zero. nada. nothing. that's your signal that she found nothing to snack on πŸ™ˆ


🧚 THREAD SAFETY 🧚

it is safe to call this function from any thread. go off, multithreaded queen 🌈


⭐ AVAILABILITY ⭐

this function is available since SDL 3.2.0. if you're on anything older, bestie, it's simply not there πŸ’€


🌸 SEE ALSO 🌸


lowkey reminder: str must not be NULL, and the number gets clamped rather than overflowing. no undefined behavior shenanigans here, just tidy clamped vibes πŸ’–

and that's the whole page, bestie!! brought to you by Simple Directmedia Layer β€” this is SDL 3.4.18, SDL_wcstol(3), mwah, love u, go parse something wide πŸ’…βœ¨

πŸ“¦ where this page comes from