0

Well this was unexpected. AVR libc has many the variants of printf, including vprintf, but is missing vprintf_P. Is this really just not present or implemented elsewhere?

Ana
  • 470
  • 2
  • 7
  • 13

1 Answers1

-1

It has vfprintf_P and stdout is a FILE. Why would you want to waste time and space with implementing vprintf_P as well?

If you really want it, you can make your own:

#define vprintf_P(...) vfprintf_P(stdout, __VA_ARGS__)

Incidentally, the source code to vprintf looks like this:

int
vprintf(const char *fmt, va_list ap)
{
    return vfprintf(stdout, fmt, ap);
}

That does exactly the same job as a preprocessor macro - just forwards your request on to the FILE-based function.

It is actually more efficient to use a preprocessor macro than needlessly nesting functions like that - less stack usage, less calls, etc (unless the compiler happens to choose to inline that function, which since it is in a library it likely won't).

The non-FILE based functions can be considered simple wrapper functions to the FILE-based ones. They are mostly provided for convenience, but are actually completely redundant and can all be replaced with direct calls to the FILE-based variant. They mostly still exist purely for historical compatibility. And since _P is specific to AVR libc there is nothing historical for it to be compatible with.

Majenko
  • 103,876
  • 5
  • 75
  • 133
  • That wouldn't be a good explanation for why it *does* have `printf`, `sprintf`, `snprintf`, `vsprintf`, `vsnprintf`, `fprintf`, `vfprintf` and all of their `_P` variants, would it? – Ana May 03 '16 at 14:15
  • It would be just idiotic to miss out `printf`. All the others either take a file or string as their target, which means they are the *base* ones. All other functions can be made from them. You don't like it? Then submit a patch to the repository and stop complaining. – Majenko May 03 '16 at 14:23
  • Wow. Fair question met with an obnoxious attitude. Okay, I'm going to go waste everyone's time and space with the patch! – Ana May 03 '16 at 14:39
  • I was going to say the same thing - fair answer met with an obnoxious attitude. You ask a question, get the answer, but don't like that answer because it doesn't agree with the answer you have already formulated inside your head, so start with the 'tude. – Majenko May 03 '16 at 14:43
  • I asked yes/no question. I would've accepted the answer "no, it's not implemented". I didn't ask for your opinion on whether the function is a waste of time and space, did I? It's also a laughable answer in itself since you yourself illustrated that it's a trivial one-liner. That's okay. This is all public. Let others judge. – Ana May 03 '16 at 14:46
  • So you don't think it's even slightly valuable that, since as you say this is public, other people might not want to know why it might not have been implemented, and how to implement it themselves should they want to? Maybe you should have privately emailed one of the developers of libc instead. – Majenko May 03 '16 at 14:48