SDL_ltoa(3)

✨ SDL_ltoa ✨

okay bestie, welcome to the SDL3 FUNCTIONS corner of the man pages, this one's SDL_ltoa(3) and she's here to turn your long integer into a string πŸ’–


🌸 NAME 🌸

SDL_ltoa β€” convert a long integer into a string. that's it, that's the job, and she does it flawlessly πŸ’…


πŸŽ€ SYNOPSIS πŸŽ€

#include <SDL3/SDL_stdinc.h>

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

πŸ¦‹ DESCRIPTION πŸ¦‹

so here's the tea β˜• β€” this one requires you to specify a radix for the string format. like, no radix, no conversion, she's not guessing for you.

  • specifying 10 produces a decimal number
  • 16 gives you hexadecimal
  • etc., you get the vibe ✨

and the radix must be in the range of 2 to 36. that's the whole range, don't try to be cute with it.

😭 GIRL. WARNING. this function will overflow a buffer if str is not large enough to hold the output! no cap, it will just keep writing. it is not checking. it does not care. πŸ’€

so if you're not about that life, it may be safer to use SDL_snprintf to clamp output, or SDL_asprintf to allocate a buffer. otherwise? it genuinely doesn't hurt to allocate much more space than you expect to use β€” and bestie, don't forget the possible negative signs, the null terminator bytes, etc. those little guys add up 🫢


🌈 FUNCTION PARAMETERS 🌈

  • value β€” the long integer to convert. your raw number, the main character πŸ‘‘
  • str β€” the buffer to write the string into. please make it big enough, i am begging πŸ™ˆ
  • radix β€” the radix to use for string generation. 2 through 36, that's the rule ⭐

πŸ’œ RETURN VALUE πŸ’œ

returns str. that's it. she hands you back the buffer you gave her, iconic behaviour honestly πŸ’…


🧚 THREAD SAFETY 🧚

it is safe to call this function from any thread. yes bestie, go wild, thread away ✨


⭐ AVAILABILITY ⭐

this function is available since SDL 3.2.0. so if you're on something older... no she's not there yet πŸ’€


πŸ”₯ SEE ALSO πŸ”₯

go read those too, they're the whole friend group 🫢


mwah πŸ’– this has been your girl from the Simple Directmedia Layer squad, running SDL 3.4.18 energy, and yeah β€” this was SDL_ltoa(3), periodt. πŸŽ€βœ¨πŸ¦‹

πŸ“¦ where this page comes from