printf versus vsnprintf

19 Dec 2010

For my Atmega environment I programmed my own display_printf (see below). Now I want to use the same api for the mbed Serial module, but the compiler doesnt know where to find va_list, va_start and va_end.

Regards...

Wijnand

/*****************************************************************//**
* \brief    display_printf
*
* This function supports...
*
* \author    W.Nijs.
* \date       28-05-2010
* \param   
*********************************************************************/

static char nhd_buffer[NHD_BUFFER_SIZE];    // output buffer

void display_printf(char *format, ...) {

uint8 i = 0;
va_list    args;

va_start(args, format);
vsnprintf(nhd_buffer, NHD_BUFFER_SIZE, format, args);
va_end(args);

// output until buffer is empty

while (nhd_buffer[i] != '\0') {
myUART.putc(nhd_buffer[i]);
i++;
}

return;
}

19 Dec 2010

I ran into the same problem recently. I'm accustomed to using log4pic, which is a port of log4c ( http://log4c.sourceforge.net/ ). I wanted to use this in my mbed program, so I started trying to port it but gave up because the online compiler did not include the va_start, va_end and vsnprintf functions.

Sorry, I do not know the answer, but I am also interested if anyone else could help.

19 Dec 2010

try...

#include <stdarg.h>
20 Dec 2010

Andy K wrote:

try...

#include <stdarg.h>

Well, the code will now compile, so it's finding some definition of vprintf - but what I'm really trying to do is print to the USB serial port. The Serial class doesn't have a implementation of vprintf, so I can't just call pc.vprintf() ... Do I have to do something special to tell vprintf where it should send output?

20 Dec 2010

I think you are going to need to use the char buffered version as you were originally above. Also, you may like to use a buffered serial system like MODSERIAL to print to a circular buffer rather than waiting for all serial chars to transmit.