SDL_swprintf(3)
π SDL_swprintf(3) π
okay bestie, welcome to the SDL3 FUNCTIONS section of the manual, and today's main character is SDL_swprintf. she formats wide strings and she does NOT need a whole C runtime to do it. iconic behavior honestly. π
β¨ NAME β¨
SDL_swprintf β this works exactly like swprintf() but doesn't require access to a C runtime. no cap.
πΈ SYNOPSIS πΈ
#include <SDL3/SDL_stdinc.h>
int SDL_swprintf(wchar_t *text, size_t maxlen, const wchar_t *fmt, ...);
π¦ DESCRIPTION π¦
so what she does is format a wide string of up to maxlen-1 wchar_t values, converting each '%' item using the values you hand her through the variable arguments. cute, right?
now here's the part where she's lowkey better than some C runtimes: those runtimes be beefing over what to do with strings that are too big, but SDL_swprintf just null-terminates the output, treating that null-terminator as part of the maxlen count. but heads up bestie β if maxlen is zero, then no wide characters get written at all. none. zero. the void. π
she returns the number of _wide characters_ (not _codepoints_, bestie, those are different things) that should be written, not counting the null-terminator character. so if what she returns is a number >= maxlen, that means your output string got truncated. and if she returns a negative value? that's an error, she's going through it. π
β οΈ also pls pls pls: referencing the output string's pointer with a format item is undefined behavior. don't do it. not even a little. π
π FUNCTION PARAMETERS π
textβ the buffer you're writing the wide string into. Must not beNULL. fr fr, not optional.maxlenβ the maximumwchar_tvalues to write, including the null-terminator. yes, she counts it. she's thorough.fmtβ aprintf-style format string. Must not beNULLeither. both of these gotta be real....β a list of values to be used with the format string. spill the tea, she'll format it. π
β RETURN VALUE β
Returns the number of wide characters that should be written, not counting the null-terminator char β or a negative value on error. that's it, that's the vibe check.
π§ THREAD SAFETY π§
It is safe to call this function from any thread. yes queen, multithread away. π«Ά
π AVAILABILITY π
This function is available since SDL 3.2.0. so if you're on something older, she's not there yet, sorry bestie. π
π‘ reminder:textandfmtmust not beNULL,maxlenof zero writes nothing at all, and touching the output pointer from inside a format item is undefined behavior. remember those three and you're golden. β¨
and that's the whole page, bestie!! this was brought to you by the Simple Directmedia Layer girlies, documenting SDL 3.4.18, and it's giving SDL_swprintf(3) energy all day long. go format something wide. slay. ππ¦πΈ
π¦ where this page comes from
- fedora 43: SDL3-devel 3.4.18-1.fc43 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 43: SDL3-devel 3.4.18-1.fc43 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 44: SDL3-devel 3.4.18-1.fc44 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 44: SDL3-devel 3.4.18-1.fc44 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms