AceCommon  1.1
Arduino library for low-level common functions and features with no external dependencies
Functions | Variables
printfTo.h File Reference
#include <stdarg.h>
#include <Arduino.h>
Include dependency graph for printfTo.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void ace_common::vprintfTo (Print &printer, const char *fmt, va_list args)
 Helper function for implementing the printfTo() function.
 
void ace_common::printfTo (Print &printer, const char *fmt,...)
 A printf() that works on an Arduino Print object using the built-in vsnprintf(). More...
 

Variables

const int ace_common::PRINTF_TO_BUF_SIZE = 192
 Maximum size of the internal stack buffer used by printfTo().
 

Detailed Description

Implement a printfTo() that accept formatting strings like printf() and prints the result to the given Print object. This is intended to be used on platforms whose Print does not provide a Print.printf() function, for example, the original Arduino UNO or Nano. I finally got tired of writing multiple lines of SERIAL_PORT_MONITOR.print() for debugging.

NOTE: These must be implemented as inline function to allow the compiler to remove unused functions from the binary. For some reason, on AVR, ESP8266 and ESP32 compilers, link-time-optimization does not seem to work well. If these functions are defined in a .cpp file, they are included in the binary, even if they are not reference at all by anything. This causes the binary to be about 700 (AVR) to 1000 (ESP32) bytes larger in flash memory.

Being inlined here means that <Arduino.h> must be included here, which can cause some problems in files that try to clobber macros defined in <Arduino.h>.

Definition in file printfTo.h.

Function Documentation

◆ printfTo()

void ace_common::printfTo ( Print &  printer,
const char *  fmt,
  ... 
)
inline

A printf() that works on an Arduino Print object using the built-in vsnprintf().

Append a '\n' at the end of the string to print a newline. This is intended to be used on platforms without a built-in Print.printf() function, for example, the original Arduino UNO or Nano.

Definition at line 51 of file printfTo.h.