Sysop: | Amessyroom |
---|---|
Location: | Fayetteville, NC |
Users: | 43 |
Nodes: | 6 (0 / 6) |
Uptime: | 94:18:47 |
Calls: | 290 |
Calls today: | 1 |
Files: | 904 |
Messages: | 76,378 |
Is there something in "C" that allows dynamic flexibility of strings?
Inspecting some of my "C" source code here I noticed a construct that
I dislike...
static char buf[32]; // sufficient space for ansi sequence
...
sprintf (buf, "\033[38;5;%dm%c\033[0m", ...);
On 2024-12-19, BlueManedHawk <bluemanedhawk@invalid.invalid> wrote:
The ‘asprintf’ subroutine is standardized by POSIX.1-2024, meaning
that you can use it now and blame somebody else if it doesn't work.
If you
Regardless of how it is made visible, you can detect it via a compile
test in a configure script, and provide your own if it wasn't found:
#if !HAVE_ASPRINTF
int asprintf(char **out, const char *fmt, ...)
{
... // more or less trivial to implement using malloc, realloc and
vsprintf
}
#endif
BTW, is there no wchar_t version of this?
can't target POSIX, the subroutine is also _theoretically_
available through the feature-test macro ‘__STDC_WANT_LIB_EXT2__’, assuming that ‘__STDC_ALLOC_LIB__’ is a predefined macro, but gLibC does not pay
When would it be the case that you can't target POSIX, but *can* mess
around with some the internal feature test macros of some specific
POSIX vendor? :)
The ‘asprintf’ subroutine is standardized by POSIX.1-2024, meaning that you can use it now and blame somebody else if it doesn't work. If you
can't target POSIX, the subroutine is also _theoretically_ available
through the feature-test macro ‘__STDC_WANT_LIB_EXT2__’, assuming that ‘__STDC_ALLOC_LIB__’ is a predefined macro, but gLibC does not pay
On Thu, 19 Dec 2024 19:47:28 -0000 (UTC)
Kaz Kylheku <643-408-1753@kylheku.com> wrote:
On 2024-12-19, BlueManedHawk <bluemanedhawk@invalid.invalid> wrote:
The ‘asprintf’ subroutine is standardized by POSIX.1-2024, meaning
that you can use it now and blame somebody else if it doesn't work.
If you
Regardless of how it is made visible, you can detect it via a compile
test in a configure script, and provide your own if it wasn't found:
#if !HAVE_ASPRINTF
int asprintf(char **out, const char *fmt, ...)
{
... // more or less trivial to implement using malloc, realloc and
vsprintf
Don't you mean, vsnprintf ?
[...]
On 2024-12-19, Michael S <already5chosen@yahoo.com> wrote:
On Thu, 19 Dec 2024 19:47:28 -0000 (UTC)
Kaz Kylheku <643-408-1753@kylheku.com> wrote:
On 2024-12-19, BlueManedHawk <bluemanedhawk@invalid.invalid>
wrote:
The ‘asprintf’ subroutine is standardized by POSIX.1-2024,
meaning that you can use it now and blame somebody else if it
doesn't work. If you
Regardless of how it is made visible, you can detect it via a
compile test in a configure script, and provide your own if it
wasn't found:
#if !HAVE_ASPRINTF
int asprintf(char **out, const char *fmt, ...)
{
... // more or less trivial to implement using malloc, realloc
and vsprintf
Don't you mean, vsnprintf ?
That detail will become obvious when you try to implement it.
Em 12/19/2024 7:06 PM, Kaz Kylheku escreveu:
On 2024-12-19, Michael S <already5chosen@yahoo.com> wrote:
On Thu, 19 Dec 2024 19:47:28 -0000 (UTC)
Kaz Kylheku <643-408-1753@kylheku.com> wrote:
On 2024-12-19, BlueManedHawk <bluemanedhawk@invalid.invalid>
wrote:
The ‘asprintf’ subroutine is standardized by POSIX.1-2024,
meaning that you can use it now and blame somebody else if it
doesn't work. If you
Regardless of how it is made visible, you can detect it via a
compile test in a configure script, and provide your own if it
wasn't found:
#if !HAVE_ASPRINTF
int asprintf(char **out, const char *fmt, ...)
{
... // more or less trivial to implement using malloc, realloc
and vsprintf
Don't you mean, vsnprintf ?
That detail will become obvious when you try to implement it.
I did on implementation in 2020 (not using it)
http://thradams.com/vadsprintf.html
The standard should have a string stream compatible with FILE because
- differently of asprintf - if cannot be implemented separately.
A function printing in a FILE* fprint also should be able to print in
a string stream.
For my needs a string stream is better I am using this https://github.com/thradams/cake/blob/main/src/osstream.c Unfortunately
it is not compatible with FILE*.