mpaland/printf

Rename functions and use macros to avoid conflicts with STD

reliasn opened this issue · 2 comments

In printf.h you would have something like this:

void x_putchar(char character);
int x_printf(const char* format, ...);
int x_sprintf(char* buffer, const char* format, ...);
int x_snprintf(char* buffer, size_t count, const char* format, ...);
int x_vsnprintf(char* buffer, size_t count, const char* format, va_list va);
int x_fctprintf(void (*out)(char character), const char* format, ...);

Along with a set of macros:

#define vsnprintf x_vsnprintf
#define snprintf x_snprintf
...

This is what tinyprintf does and it is very convenient because it avoids conflicts with the STD printf functions.

I'm actually coming from tinyprintf because it lacks float support and doesn't seem to be updated often.

@reliasn thanx for your feedback!
I know tinyprintf, receiving no more updates may not be a bad thing, if the code is mature and bug free. 😃
tinyprintf just doesn't pass the test suite very well.

Anyway, the old discussion about already defined functions in the standard lib. I'm really well aware of that problem. Normally it's not a problem when you do not link against the standard, but if you need due to other functions, things become difficult.

I tried to avoid using function redeclaring defines, because not all compilers fully support variadic macrcos (even if they should) by now.

A possible solution might be a combination like that:
In printf.c:

#ifdef OVERRIDE_LIBC
int x_printf(const char    )
#else
int printf(const char    )
#endif
{
  // impl
}

And in printf.h:

#ifdef OVERRIDE_LIBC
#define printf( , ...)  x_printf(const char  , ...)
#else
int printf(const char  , ...);
#endif

In the case above a variadic macro is not necessarily needed.
Solution is in work.