4 #include "mbed/xprintf.h"
6 #define STRING_STACK_LIMIT 120
9 int __xprintf(const char* format, ...) { return 0; }
13 Serial ser(UART_TX, UART_RX);
15 /* TODO: Need small implementation for embedded */
16 int xprintf(const char* format, ...)
18 /* copy from mbed/common/RawSerial.cpp */
20 va_start(arg, format);
21 int len = vsnprintf(NULL, 0, format, arg);
22 if (len < STRING_STACK_LIMIT) {
23 char temp[STRING_STACK_LIMIT];
24 vsprintf(temp, format, arg);
27 char *temp = new char[len + 1];
28 vsprintf(temp, format, arg);
35 /* Fail: __builtin_va_arg_pack?
36 * https://gcc.gnu.org/onlinedocs/gcc-4.3.5/gcc/Constructing-Calls.html#Constructing-Calls
37 void *arg = __builtin_apply_args();
38 void *ret = __builtin_apply((void*)(&(ser.printf)), arg, 100);
41 /* Fail: varargs can not be passed to printf
42 //int r = ser.printf("test %i\r\n", 123);
44 va_start(arg, format);
45 int r = ser.printf(format, arg);