You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm new to SDL. I saw a neat function called SDL_Log, which seemed to do exactly what I wanted.
Until one one fine day I tried SDL_Log("%g", 1.0") and got a blank line, and was very confused.
After some time spent trying to see whether anyone on the internet had the same issue, I eventually gave up and asked this question on stack overflow, which was answered surprisingly quickly: https://stackoverflow.com/questions/69216803/sdl-log-doesnt-seem-to-support-g-and-e-specifiers
As a result of this mini-(mis)adventure, I think I can offer several suggestions that would have made using SDL easier.
The suggestions are in two categories, code and docs. Let's start with code, because I have fewer things to say there:
First, perhaps it's worth defining HAVE_VSNPRINTF for sufficiently recent versions of VC++ (maybe 2015 or so?)
Second, perhaps it's worth improving SDL's homegrown vsnprintf so it vaguely conforms to the ISO standard, or at least supports the most common flags. (E.g., it supports %f, but not the uppercase variant %F, and it supports neither %e nor %g, which must be pretty common.)
Okay, that's it for code suggestions. I also have some docs suggestions. I give some specific wording here, but my wording is mostly a strawman proposal; the info is mostly right I think (or hope).
First, for SDL_Log, the wiki page should mention something like
This function delegates to SDL_vsnprintf in order to interpret the format string. See the documentation for that function for more info.
Actually it looks like the SDL wiki doesn't yet document its stdio "wrappers" so that should be fixed too I guess. Once that's done, the documentation for SDL_vsnprintf should probably mostly be a stub that delegates to SDL_snprintf, since the "v" variant is mostly for advanced users. Alternatively, you could do it the other way around, and have the docs for SDL_snprintf delegate to those of SDL_vsnprintf, which is more faithful to how the code itself is structured. Or you could have both functions documented independently; duplication is annoying but probably in this case mostly harmless.
For the sake of concreteness, let's suppose we're documenting SDL_vsnprintf. Then its wiki page should mention something like this:
This function either delegates to the vsnprintf provided by your standard library (if SDL thinks your standard library has one that SDL wants to use) , or else uses a version of vsnprintf provided by SDL itself. To determine if your platform has a vsnprintf that SDL knows about and likes/trusts, simply check whether the macro HAVE_VSNPRINTF is defined, eg, by using #ifdef or by seeing whether your IDE auto-completes the name for you. There is usually no need to care about how SDL_vsnprintf is implemented, but here are some reasons why you might care after all:
Performance (SDL's version might be faster or slower than other implementations of vsnprintf)
Reproducible output for floating point numbers. E.g., should printf (“%.1f\n”,0.25) be 0.2 or 0.3? Different implementations of printf don't always agree on such corner cases.
Feature support: some standard libraries support non-standard extensions for snprintf (e.g., extra % specifiers), or support features that only became standardized in relatively recent versions of C. (See the documentation for your standard library to see what yours supports.) On the other hand, the one provided by SDL is pretty bare bones. In fact, up until version ABC, it only supported the type specifiers %i and %c; below is a table of all the specifiers as of version CURRENT; the second column is the version of SDL that first supported the given specifier.
The text was updated successfully, but these errors were encountered:
I'm new to SDL. I saw a neat function called SDL_Log, which seemed to do exactly what I wanted.
Until one one fine day I tried
SDL_Log("%g", 1.0")
and got a blank line, and was very confused.After some time spent trying to see whether anyone on the internet had the same issue, I eventually gave up and asked this question on stack overflow, which was answered surprisingly quickly:
https://stackoverflow.com/questions/69216803/sdl-log-doesnt-seem-to-support-g-and-e-specifiers
As a result of this mini-(mis)adventure, I think I can offer several suggestions that would have made using SDL easier.
The suggestions are in two categories, code and docs. Let's start with code, because I have fewer things to say there:
First, perhaps it's worth defining HAVE_VSNPRINTF for sufficiently recent versions of VC++ (maybe 2015 or so?)
Second, perhaps it's worth improving SDL's homegrown vsnprintf so it vaguely conforms to the ISO standard, or at least supports the most common flags. (E.g., it supports %f, but not the uppercase variant %F, and it supports neither %e nor %g, which must be pretty common.)
Okay, that's it for code suggestions. I also have some docs suggestions. I give some specific wording here, but my wording is mostly a strawman proposal; the info is mostly right I think (or hope).
First, for SDL_Log, the wiki page should mention something like
Actually it looks like the SDL wiki doesn't yet document its stdio "wrappers" so that should be fixed too I guess. Once that's done, the documentation for SDL_vsnprintf should probably mostly be a stub that delegates to SDL_snprintf, since the "v" variant is mostly for advanced users. Alternatively, you could do it the other way around, and have the docs for SDL_snprintf delegate to those of SDL_vsnprintf, which is more faithful to how the code itself is structured. Or you could have both functions documented independently; duplication is annoying but probably in this case mostly harmless.
For the sake of concreteness, let's suppose we're documenting SDL_vsnprintf. Then its wiki page should mention something like this:
The text was updated successfully, but these errors were encountered: